6

VeraCode を実行した後、次のコード フラグメントで次のエラー「HTTP ヘッダーの CRLF シーケンスの不適切な中和 ('HTTP 応答分割')」が報告されました。

protected override void InitializeCulture() {
        //If true then setup the ability to have a different culture loaded
        if (AppSettings.SelectLanguageVisibility) {
            //Create cookie variable and check to see if that cookie exists and set it if it does.
            HttpCookie languageCookie = new HttpCookie("LanguageCookie");
            if (Request.Cookies["LanguageCookie"] != null)
                languageCookie = Request.Cookies["LanguageCookie"];

            //Check to see if the user is changing the language using a query string.
            if (Server.UrlDecode(Request.QueryString["l"]) != null)
                languageCookie.Value = Server.UrlDecode(Request.QueryString["l"]);

            //Check to make sure the cookie isn't null and set the culture variable to auto if it is and the value of the cookie if it isn't.
            if (languageCookie.Value == null)
                languageCookie.Value = string.Empty;

            string culture = languageCookie.Value.ToString();
            if (string.IsNullOrEmpty(culture))
                culture = "Auto";

            //Use to set the Culture and UI Culture.
            this.UICulture = culture;
            this.Culture = culture;
            if (culture != "Auto") {
                //If culture is changed set the new Current Culture and CurrentUICulture.
                System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(culture);
                System.Threading.Thread.CurrentThread.CurrentCulture = ci;
                System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
            }

            //Update the cookie value with the new culture and initialize the culture.
            Response.Cookies.Set(languageCookie);
            Response.Cookies["LanguageCookie"].Expires = DateTime.Now.ToLocalTime().AddYears(1);
            Response.Cookies["LanguageCookie"].HttpOnly = true;
        }
        else {
            //Else keep language as English if localization is not enabled.
            this.UICulture = "en";
            this.Culture = "en";
        }

        base.InitializeCulture();
    }

レポートは、次のコードを含む行を指しています: Response.Cookies.Set(languageCookie); そのエラーを解消するためにどのような修正を使用できますか?

ありがとう

4

6 に答える 6

6

この問題を解決する最も簡単な方法は、esapi jar にある ESAPI httputilities を使用することです。使用できます

ESAPI.httpUtilities().setHeader(response,param,value);
ESAPI.httpUtilities().addCookies(response, param,value);

および他のタスクの同様の方法。クラスパスに ESAPI.properrties を設定する必要があります。これは、Java 用に実装した方法です。他の言語でも同じ機能を利用できます。

追加の作業は必要なく、ベラコードで問題を解決します。

于 2014-04-15T06:04:46.830 に答える
5

問題はラインだからだと思います

languageCookie.Value = Server.UrlDecode(Request.QueryString["l"]);

(信頼されていない) ユーザー入力 (つまりRequest.QueryString["l"]) を受け入れます。に格納する前に、関数呼び出しを追加して、そのクエリ文字列パラメーターからキャリッジ リターンまたはライン フィード文字 (%0dおよびのようなエンコードされた同等のものを含む) を削除してみてください。%0alanguageCookie

たとえば、その行を次のように変更してみてください。

languageCookie.Value = Server.UrlDecode(Request.QueryString["l"])
                         .Replace("\r", string.Empty)
                         .Replace("%0d", string.Empty)
                         .Replace("%0D", string.Empty)
                         .Replace("\n", string.Empty)
                         .Replace("%0a", string.Empty)
                         .Replace("%0A", string.Empty);

ただし、それはおそらく少しクリーンアップする必要があります (現時点では、私は C# プログラマーではありません)。

こちらもご覧ください

于 2014-04-12T17:40:28.070 に答える
0

説明

関数呼び出しに、HTTP 応答分割の欠陥が含まれています。サニタイズされていないユーザー入力を HTTP ヘッダーに書き込むと、攻撃者はブラウザーによってレンダリングされた HTTP 応答を操作できるようになり、キャッシュ ポイズニングやクロスサイト スクリプティング攻撃につながる可能性があります。

推奨事項

HTTP 応答の作成に使用されるユーザー提供のデータから、予期しないキャリッジ リターンとライン フィードを削除します。可能な場合は集中型のデータ検証ルーチンを使用して、ユーザー提供の入力を常に検証して、期待される形式に準拠していることを確認します。

問題コード

response.setHeader(headerKey,headerValue); 
response.addHeader(headerKey, headerValue);

固定コード

DefaultHTTPUtilities httpUtilities = new DefaultHTTPUtilities(); 
httpUtilities.setHeader(headerKey,headerValue); 
httpUtilities.addHeader(response, headerKey,headerValue);
于 2015-11-12T07:09:38.123 に答える