3

Stunnel (SSL を削除するため) と HAProxy をロード バランサーで使用し、HTTP 経由で IIS に要求を送信します。

私たちが抱えている問題は、サイト (ASP.NET) が安全な方法で Cookie を設定すること、つまり、requireSSL 属性を true に設定することです。

この属性を設定してサイトに HTTPS リクエストを送信すると、次のエラーが発生します。

The application is configured to issue secure cookies. These cookies require the browser to issue the request over SSL (https protocol). However, the current request is not over SSL.

リクエストがロードバランサーから SSL 経由で送信された場合、ウェブサーバーを信頼できますか? それとも、私たちのサイトには SSL 経由でしかアクセスできない (443 のみが開いている) ため、これは問題ではありませんか?

4

2 に答える 2

2

ASP.NET MVC 3 ユーザー (私たち) の場合は、私がまとめた次の GlobalFilter を使用してこれを処理することもできます。これにより、返された Cookie を保護できます。

namespace MyNamespace
{
    public class SecureCookiesAttribute : FilterAttribute, IResultFilter
    {
        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            foreach (string cookieName in filterContext.HttpContext.Response.Cookies.AllKeys)
                filterContext.HttpContext.Response.Cookies[cookieName].HttpOnly = true;

            if (filterContext.HttpContext.Request.IsLocal)
                return;

            foreach (string cookieName in filterContext.HttpContext.Response.Cookies.AllKeys)
                filterContext.HttpContext.Response.Cookies[cookieName].Secure = true;
        }

        public void OnResultExecuted(ResultExecutedContext filterContext) { }
    }
}

これにより、任意の Cookie に HTTPOnly フラグが設定されます。リクエストがローカル以外のソースからのものである場合は、セキュア フラグも設定されます。これにより、HTTPS ではなく HTTP を介してローカル デバッグを行うことができます (ただし、すべてが HTTPS を介して行う場合は、このチェックを簡単に削除できます)。

于 2011-06-17T08:47:11.327 に答える
2

これの代わりに:

FormsAuthentication.SetAuthCookie(email, false);

これを試して:

var cookie = FormsAuthentication.GetAuthCookie(email, false);
cookie.Secure = true;
HttpContext.Current.Response.Cookies.Add(cookie);

ASP.NET MVC を使用している場合は、応答のすべての Cookie にセキュア フラグを設定するグローバル アクション フィルターを使用することもできます。

于 2011-06-16T21:52:56.410 に答える