修复CWE-113:HTTP标头中CRLF序列的中和不正确(' HTTP响应拆分')

时间:2017-03-30 06:22:19

标签: c#

运行veracode扫描后,我收到了CWE 113错误。我找到了一个替换cookie值的解决方案,但问题仍然没有解决。

  

修复CWE-113:HTTP中CRLF序列的中和不正确   标题(' HTTP响应拆分')

string ReplaceHTTPRequestValue(string Value)
{
    string replacedValue = string.Empty;
    if (!string.IsNullOrEmpty(Value))
    {
        replacedValue = Value.Replace("\r", string.Empty)
                                .Replace("%0d", string.Empty)
                                .Replace("%0D", string.Empty)
                                .Replace("\n", string.Empty)
                                .Replace("%0a", string.Empty)
                                .Replace("%0A", string.Empty);
    }
    return replacedValue;
}

void WebTrends_PreRender()
{
    HttpCookie cookie = Request.Cookies["WT_CID"];
    string campaignIdVal = string.Empty;
    if (cookie != null)
    {
        campaignIdVal = ReplaceHTTPRequestValue(Request.Cookies["WT_CID"].Value);
    }
    else
    {
        campaignIdVal = string.Empty;
    }
}

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

string ReplaceHTTPRequestValue(字符串值) {
字符串NonCRLF = string.Empty;

        foreach (char item in Value)
        {

            NonCRLF += item.ToString().Replace("\n", "").Replace("\r","");
        }
        return NonCRLF;
    }