Re: 管理画面へのアクセスを「httpsのみ」にしたい
2015年9月23日 at 15:35
ぜひ、どういう設定がいいのかを議論したいので、他の方からも意見も伺いたいのですが…。
とりあえず、application/bootstrap/app.php に記載する方法として考えてみました。
ログイン関連ページと管理画面へのアクセスの場合はHTTPSにリダイレクトするコードです。
httponly属性を付けることを想定し、逆方向(管理画面以外にhttpsでアクセスした際にhttpに戻す)は想定していません。
use Concrete\Core\Http\Request;
use Concrete\Core\Routing\RedirectResponse;
use Concrete\Core\Url\Url;
Events::addListener('on_before_dispatch', function() {
$app = Core::make('app');
$request = Request::getInstance();
if ($request->getScheme() == 'http') {
if (
$request->getPath() == '/login' ||
$request->matches('/login/*') ||
$request->matches('/dashboard/*')
) {
$url = Url::createFromUrl($request->getUri());
$url->setScheme('https');
$response = new RedirectResponse($url);
}
}
if (isset($response)) {
$response->send();
exit;
}
});
http://gist.github.com/hissy/7cb3f462f489c118d9fc
ただ、試してみたところ、httpなURLにアクセスすると、セッションが切れてしまいます…。結構不便なので、サイト全体でhttpsを強制するか、httponlyを諦めるか…な気がしてしまいます。
Your post has been saved and will be published after approval by the forum moderator.
takuro hishikawa
Re: 管理画面へのアクセスを「httpsのみ」にしたい