web.configで認証Cookieにsecureオプションを付ける。
<?xml version="1.0" encoding="shift_jis"?>
<configuration>
<system.web>
.... (中略) ....
<authentication mode="Forms">
<forms name="NETWSSample"
loginUrl="Login/Login.aspx"
protection="All"
requireSSL="true"
timeout="30" path="/" />
</authentication>
.... (中略) ....
</system.web>
</configuration>
認証CookieにHttpOnly属性やsecureオプションを付ける。
using System.Web.Security;
protected void Application_EndRequest(Object sender, EventArgs e)
{
string authCookieName = FormsAuthentication.FormsCookieName;
foreach (string sCookie in Response.Cookies)
{
if (sCookie == authCookieName)
{
// クロスサイトスクリプティング脆弱性に対する多重防衛
Response.Cookies[sCookie].Path += ";HttpOnly";
// SSLセッション外に認証クッキー情報を出さない
// (.NET Framework 1.0用)
// Response.Cookies[sCookie].Secure = true;
}
}
}
※ HttpOnly属性を付与すると、document.cookieプロパティからクッキー情報を取り出せなくなるため、安全性が高まる。ただしHttpOnly属性は、IE6SP1以降でしかサポートされていない。
参考: 「.NETエンタープライズWebアプリケーション開発技術大全Vol.4 セキュアアプリケーション設計編」4.2.6