2012-12-21 80 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的是我们最后一次扫描满意。