2012-12-21 116 views
3

我們的客戶使用Veracode的掃描工具掃描ASP.NET應用程序。除了下面的內容,我們已經解決了許多缺陷。ASP.NET Veracode的掃描問題

Improper Neutralization of CRLF Sequences in HTTP Headers ('HTTP Response Splitting') 
(CWE ID 113)(1 flaw) in the line 

HttpContext.Current.Response.AddHeader("Content-Disposition", contentDisposition); 

這是相應的代碼:

public static void DownloadFile(string fileName, byte[] dByteData, bool isNoOpen = false) 
     { 

      byte[] fileContents = new byte[] { }; 
      string contentDisposition = string.Empty; 
      fileContents = dByteData; 
      if (string.IsNullOrWhiteSpace(fileName)) 
      { 
       return; 
      } 
      fileName = fileName.Replace("\n", "").Replace("\r", ""); 
      string contentType = "application/*.".Replace("\n", "").Replace("\r", ""); 
      contentDisposition = "attachment; filename=\"" + HttpContext.Current.Server.UrlPathEncode(fileName) + "\"";//While Downloading file - file name comes with junk characters 
      contentDisposition= contentDisposition.Replace("\n", "").Replace("\r", ""); 
      HttpContext.Current.Response.Buffer = true; 
      HttpContext.Current.Response.Clear(); 
      HttpContext.Current.Response.ClearContent(); 
      HttpContext.Current.Response.ClearHeaders(); 
      HttpContext.Current.Response.Charset = ""; 
      HttpContext.Current.Response.ContentType = contentType; 
      if (isNoOpen) 
      { 
       HttpContext.Current.Response.AddHeader("X-Download-Options", "noopen"); 
      } 
      HttpContext.Current.Response.AddHeader("Content-Disposition", contentDisposition); 
      HttpContext.Current.Response.AddHeader("Content-Length", fileContents.Length.ToString()); 
      HttpContext.Current.Response.BinaryWrite(fileContents.ToArray()); 

      HttpContext.Current.Response.End(); 
      HttpContext.Current.Response.Flush(); 
      HttpContext.Current.ApplicationInstance.CompleteRequest(); 
     } 

文件名或路徑(CWE ID 73)的外部控制

if (File.Exists(filePath)) 
      { 
       File.Delete(filePath); 
      } 

它顯示錯誤在File.Delete線。我們試圖消毒文件路徑,也用於Path.GetFullpath但徒勞而已。

回答

1

你可以得到有關調用堆棧分析缺陷原因的詳細信息(它是在應用程序的分流缺陷部分建設掃描結果在Veracode的分析中心)。有些Veracode的缺陷起源是很難沒有這些信息來了解。

1

很多時候工具,如Veracode的不明白的事實,你已經消毒的內容。它似乎缺少你的Replace()調用。我會將這一發現標記爲誤報並繼續前進。

0

對於文件名或路徑(CWE ID 73)的外部控制:

驗證filePath與像出頭:

public ValidatePath(string path) { 
    var invalidPathCharacters = System.IO.Path.GetInvalidPathChars(); 
    foreach (var a in path) 
    { 
     if (invalidPathCharacters.Contains(a)) 
     { 
      throw new Exception($"Character {a} is an invalid path character for path {path}"); 
     } 
    } 
} 

Veracode的是我們最後一次掃描滿意。