Проблемы со сканированием ASP.NET Veracode

Наш клиент использует инструмент сканирования 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, но только напрасно.


person PADMANABHAN KANNAN    schedule 21.12.2012    source источник


Ответы (4)


Вы можете получить более подробную информацию о происхождении уязвимости с помощью анализа стека вызовов (он доступен в разделе «Ошибки сортировки» результатов сканирования сборки приложения в Центре анализа Veracode). Без этой информации трудно понять происхождение некоторых недостатков Veracode.

person MaSEL    schedule 23.12.2012

Очень часто такие инструменты, как Veracode, не понимают того факта, что вы очистили свой контент. Кажется, отсутствуют ваши вызовы Replace(). Я бы отметил этот вывод как ложноположительный и пошел дальше.

person Vitaly Osipov    schedule 20.04.2013

Для внешнего управления именем файла или путем (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 был удовлетворен нашим последним сканированием.

person Megan McChesney    schedule 23.05.2017

Используйте атрибут veracode filepathcleanser. см. https://help.veracode.com/reader/DGHxSJy3Gn3gtuSIN2jkRQ/CWbscOAsMPyIXqASkLRTnw

person user13298957    schedule 13.04.2020
comment
Это только добавляет комментарий в статусе смягчения. Как мы можем отключить статус исправления? - person Blaise; 09.03.2021