【问题标题】:ASP.NET Veracode Scanning issuesASP.NET Veracode 扫描问题
【发布时间】:2012-12-08 16:44:12
【问题描述】:

我们的客户端使用 Veracode 扫描工具来扫描 ASP.NET 应用程序。除了以下问题,我们已经解决了许多缺陷。

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,但只是徒劳。

【问题讨论】:

    标签: asp.net veracode


    【解决方案1】:

    【讨论】:

    • 它只在缓解状态中添加评论。我们如何关闭“补救状态”?
    【解决方案2】:

    对于文件名或路径的外部控制 (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 感到满意。

    【讨论】:

      【解决方案3】:

      很多时候,像 Veracode 这样的工具并不了解您已经对内容进行了清理这一事实。它似乎缺少您的 Replace() 调用。我会将这一发现标记为误报,然后继续。

      【讨论】:

        【解决方案4】:

        您可以通过调用堆栈分析获得有关缺陷来源的更多详细信息(可在 Veracode 分析中心的应用程序构建扫描结果的“分类缺陷”部分获得)。如果没有这些信息,一些 Veracode 缺陷的来源很难理解。

        【讨论】:

          猜你喜欢
          • 2021-05-18
          • 2016-01-23
          • 2014-09-04
          • 1970-01-01
          • 2019-05-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多