标签: veracode

处理由veracode引发的跨站点脚本缺陷

我们在ASP.Net和C#中有一个遗留的Web应用程序,我们得到了大约400个以及Veracode扫描引发的跨站点脚本漏洞.我已经创建了一个示例Web应用程序并模拟了该问题,并发现每当我们使用任何字符串输入时,它就会提高它的缺陷.这样做HttpUtility.HtmlEncode(TextBox1.Text);"满足Veracode的,但是应用在所有400位这种变化是不可行的话就工作和测试工作巨量.我正在寻找在httphandler中实现一些插件,以便所有输入都在一个地方编码,我们无需在任何地方进行更改.有人可以引导我,如果这是可能的,如果是,即使你可以指导我只是接近将足够好,至少有一个方向.提前谢谢了.

StringOps strop = new StringOps();
        string txt1, txt2;
        txt1 = HttpUtility.HtmlEncode(TextBox1.Text);
        txt2 = HttpUtility.HtmlEncode(TextBox2.Text);
        Response.Write(strop.Add(txt1, txt2));
Run Code Online (Sandbox Code Playgroud)

如果我删除了HttpUtility.HTMLEncode行,Veracode会抱怨它.由于我们正在进行这种字符串操作的地方很多,因此无处不在.是否可以在单个位置实现此编码,并且所有响应和请求都应该通过该管道,例如HTTPHandler和HTTPModule.

c# asp.net veracode

6
推荐指数
1
解决办法
996
查看次数

针对MVC5的CWE-ID 100修复

根据Veracode的说法,我们的应用程序正在遭遇与技术特定输入验证问题相关的数百次CWE-ID 100"缺陷" .

根据他们的文档,修复是ModelState.IsValid在使用之前检查模型上的属性.我们在每个控制器动作上执行此操作,但我们仍然没有动作.下面是一个控制器动作示例

public async Task<ActionResult> DeliverySummary (ReportsViewModel Model)
{
    if (ModelState.IsValid)
    {
        /* Other processing occurs here */ 

        //finally return View
        return View(Model);
    }
    else 
    {
        return View();
    }
}
Run Code Online (Sandbox Code Playgroud)

我们有System.ComponentModel.DataAnnotations我们的模型属性.

有没有人见过这个?

c# asp.net-mvc veracode asp.net-mvc-5

6
推荐指数
1
解决办法
1383
查看次数

Veracode 出现“资源关闭或释放不当”错误,为什么?

这段代码有什么问题?此外我该如何解决它?

public class BodyStreamMiddleware
{
    private readonly RequestDelegate _next;

    public BodyStreamMiddleware(RequestDelegate next) { _next = next; }

    public async Task Invoke(HttpContext context)
    {
        //  Replace the FrameRequestStream with a MemoryStream.
        //  This is because the MemoryStream is rewindable, the FrameRequestStream is not.
        //  This allows ExceptionFilters to read the body for logging purposes
        string bodyAsText;
        using (var bodyReader = new StreamReader(context.Request.Body))
        {
            bodyAsText = bodyReader.ReadToEnd();
        }
        var bytesToWrite = Encoding.UTF8.GetBytes(bodyAsText);

        using (var memoryStream = new MemoryStream())
        {
            memoryStream.Write(bytesToWrite, 0, bytesToWrite.Length); …
Run Code Online (Sandbox Code Playgroud)

c# veracode .net-core

6
推荐指数
1
解决办法
4670
查看次数

CWE 73 错误 - Veracode 问题 - .net 应用程序

我在解决我的项目中的 Veracode 扫描仪预约问题时遇到了问题。我创建了一个函数来验证文件,但它没有通过 veracode 扫描仪;

这是我的函数的代码:

    public static string GetSafeFileName(string fileNameToValidate)
    {
        fileNameToValidate= fileNameToValidate.Replace("'", "''").Replace(@"../", "").Replace(@"..\", "");
        char[] blackListChars = System.IO.Path.GetInvalidPathChars();
        char[] blackListFilename = System.IO.Path.GetInvalidFileNameChars();

        foreach (var invalidChar in blackListChars)
        {
            if (fileNameToValidate.Contains(invalidChar))
            {
                fileNameToValidate = fileNameToValidate.Replace(invalidChar, ' ').Trim();
            }
        }

        string fullPath = Path.GetFullPath(fileNameToValidate);

        string directoryName = Path.GetDirectoryName(fullPath);
        string fileName = Path.GetFileName(fullPath);

        foreach (var invalidChar in blackListFilename)
        {
            if (fileName.Contains(invalidChar))
            {
                fileName = fileName.Replace(invalidChar, ' ').Trim();
            }
        }

        string finalPath = Path.Combine(directoryName, fileName);
        return finalPath;

    }
Run Code Online (Sandbox Code Playgroud)

为了修复 Veracode 扫描仪中的 …

.net c# veracode

6
推荐指数
1
解决办法
7186
查看次数

无法在 ASP.NET 中纠正 VeraCode CWE ID 918 - (SSRF)

长话短说,无论我尝试什么,VeraCode 都会继续将我的 8 行代码标记为 CWE 918 的缺陷。这是旧代码,所以我不确定为什么它会突然被标记。

这是一个示例 [offending] 方法,带有粗体标记的行

  public virtual async Task<HttpResponseMessage> Put(string controller = "", Dictionary<string, object> parameters = null, object body = null)
        {
            if (string.IsNullOrWhiteSpace(ApiBaseUrl)) return null;
            HttpResponseMessage response = null;

            using (var client = GetHttpClient())
            {
                client.BaseAddress = new Uri(ApiBaseUrl);

                if (!string.IsNullOrEmpty(Token)) client.DefaultRequestHeaders.Add("Token-Key", Token);
                if (!string.IsNullOrEmpty(DeviceId)) client.DefaultRequestHeaders.Add("DeviceId", DeviceId);

                var url = GenerateUrl(controller, parameters);

                var requestBody = GeneratedHttpContent(body);
                if (requestBody == null) requestBody = new StringContent("");

                **response = await client.PutAsync(url, requestBody);**

                await LogError(response);
                return response; …
Run Code Online (Sandbox Code Playgroud)

asp.net asp.net-mvc veracode ssrf

6
推荐指数
1
解决办法
4109
查看次数

Javascript:网页中与脚本相关的 HTML 标签的不正确中和(基本 XSS)

我正在花时间尝试修复 veracode 扫描缺陷 CWE-80 网页中与脚本相关的 HTML 标签的不正确中和(基本 XSS)。

我所做的是对后端进行 HTTP 调用,以便打开包含下载文件的 blob。

    const xhr = new XMLHttpRequest();
    xhr.open("GET", url, true);
    xhr.responseType = "arraybuffer";
    xhr.onreadystatechange =  () => {
        if (xhr.readyState === 4 && xhr.status === 200) {
            var windowUrl = window.URL || window.webkitURL;
            var blobUrl = windowUrl.createObjectURL(new Blob([xhr.response]));
            const doc = document.createElement('a');
            document.body.appendChild(doc);
            doc.href = blobUrl;
            if (filename) {
                doc.download = filename;
            }
            doc.click();
            windowUrl.revokeObjectURL(url);
        }
    }
        xhr.send();
Run Code Online (Sandbox Code Playgroud)

veracode 抱怨这一行

document.body.appendChild(doc);
Run Code Online (Sandbox Code Playgroud)

对 Node.appendChild() 的调用包含跨站点脚本 (XSS) 缺陷。该应用程序使用不受信任的输入填充 HTTP 响应,从而允许攻击者嵌入恶意内容,例如 Javascript 代码,这些内容将在受害者浏览器的上下文中执行。XSS …

javascript xss xmlhttprequest owasp veracode

6
推荐指数
1
解决办法
6354
查看次数

如何修复“ HTTP标头中CRLF序列的不正确中和('HTTP响应拆分')”

运行VeraCode后,它在以下代码片段中报告了以下错误“ HTTP标头中的CRLF序列未正确中和('HTTP响应拆分')”:

protected override void InitializeCulture() {
        //If true then setup the ability to have a different culture loaded
        if (AppSettings.SelectLanguageVisibility) {
            //Create cookie variable and check to see if that cookie exists and set it if it does.
            HttpCookie languageCookie = new HttpCookie("LanguageCookie");
            if (Request.Cookies["LanguageCookie"] != null)
                languageCookie = Request.Cookies["LanguageCookie"];

            //Check to see if the user is changing the language using a query string.
            if (Server.UrlDecode(Request.QueryString["l"]) != null)
                languageCookie.Value = Server.UrlDecode(Request.QueryString["l"]);

            //Check to make sure the cookie isn't null …
Run Code Online (Sandbox Code Playgroud)

c# cookies veracode

5
推荐指数
2
解决办法
1万
查看次数

如何中和 HTTP 标头中的 CRLF 序列

我已经通过这个链接。[如何修复“HTTP 标头中 CRLF 序列的中和不当('HTTP 响应拆分')”

但它没有给我解决方案。

我的代码还给出了错误“HTTP 标头中 CRLF 序列的中和不当('HTTP 响应拆分')CWE ID 113”。

我的代码片段是::

Cookie newloginCookie = new Cookie("CMCLoginCookie", userName + ":" + password);
                                newloginCookie.setMaxAge(24 * 60 * 60 * 1000);
                                response.addCookie(newloginCookie);
Run Code Online (Sandbox Code Playgroud)

在 veracode scan 中,最后一行给出了错误。不知道该怎么做。

java veracode

5
推荐指数
1
解决办法
6936
查看次数

Veracode XML外部实体参考(XXE)

我在我的veracode报告中得到了下一个发现:XML外部实体参考的不当限制('XXE')(CWE ID 611)参考下面的代码

...

>     DocumentBuilderFactory dbf=null;      DocumentBuilder db = null;      try {       dbf=DocumentBuilderFactory.newInstance();  
>       dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); 
>       dbf.setExpandEntityReferences(false); 
>       dbf.setXIncludeAware(false);        dbf.setValidating(false);       db =
> dbf.newDocumentBuilder();   
>       InputStream stream = new ByteArrayInputStream(datosXml.getBytes());
>       Document doc = null;            doc= db.parse(stream, "");  
Run Code Online (Sandbox Code Playgroud)

...

我一直在研究,但我没有找到这个发现的理由或使它消失的方法.你能告诉我怎么做吗?

java veracode xxe

5
推荐指数
1
解决办法
7853
查看次数

使用java.security.SecureRandom生成随机单词时,Veracode的Entropy不足

我创建了一个使用org.apache.commons.lang.RandomStringUtils生成随机单词(字母数字)的类.

    public String randomWord(int wordLength) {
        return RandomStringUtils.random(wordLength, 0, 0, true, true, null, new SecureRandom());
    }
Run Code Online (Sandbox Code Playgroud)

这段代码工作正常,但是当我把它提交给Veracode时,我得到一个中等错误"Insufficient Entropy(CWE ID 331)"

我认为使用SecureRandom足以修复此错误,但事实并非如此,我不知道为什么.

为什么使用SecureRandom不够好或不够安全?
有没有办法使用org.apache.commons.lang.RandomStringUtils而不会让Veracode不开心?是否有任何其他安全库可用于生成安全的随机字母数字单词?

java random entropy veracode

5
推荐指数
1
解决办法
1583
查看次数