【问题标题】:How to againts XSS when write file stream to outputStream?将文件流写入 outputStream 时如何对抗 XSS?
【发布时间】:2021-09-17 09:16:24
【问题描述】:

Veracode 报告我的应用程序在将文件流写入 outputStream 时存在 XXS 风险。我正在尝试使用 ESAPI 来解决这个问题,但仍然报告了同样的问题。我该怎么办?

public static int copyStream(InputStream in, OutputStream out, int buffer)
        throws IOException {
    
    byte buf[] = new byte[buffer];
    int len;
    int ttl = 0;
    while ((len = in.read(buf)) != -1) {
        try {
            buf = ESAPI.validator().getValidFileContent(IOUtil.class.getName(), buf, 50000000, false);
            out.write(buf, 0, len);
            ttl += len;
        } catch (IntrusionException e) {
            e.printStackTrace();
        } catch (ValidationException e) {
            e.printStackTrace();
        }
    }
    out.flush();
    in.close();
    out.close();
    return ttl;
}

【问题讨论】:

    标签: java xss esapi


    【解决方案1】:

    如果该验证器与DefaultValidator 相同,则它仅检查文件大小。但它正在检查缓冲区的大小,而不是文件,所以可能不会做任何事情。

    将文件发送到浏览器时,如果内容类型不是 html 类型,则不会出现任何 XSS 问题。如果你将 content-type 设置为application/octet-stream,那么它将被下载而不执行任何操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-23
      • 1970-01-01
      • 2013-05-29
      • 2013-05-28
      • 1970-01-01
      • 2011-07-04
      • 2012-03-23
      • 1970-01-01
      相关资源
      最近更新 更多