【问题标题】:Pass Veracode CWE 117 (Improper Output Neutralization for Logs) only with replaceAll("\r", "_").replaceAll("\n", "_")仅使用 replaceAll("\r", "_").replaceAll("\n", "_") 通过 Veracode CWE 117(不正确的日志输出中和)
【发布时间】:2018-03-15 19:53:58
【问题描述】:

我在一些论坛上读到这样的神话,即通过执行此类操作足以通过 Veracode CWE 117(日志的不正确输出中和)问题。 有人可以确认是否是这种情况吗?

 message.replaceAll("\r", "_").replaceAll("\n", "_");

来自这个话题How to fix Veracode CWE 117 (Improper Output Neutralization for Logs) ,我明白我需要做这样的事情

ESAPI.encoder().encodeForHTML(message);

【问题讨论】:

    标签: amazon-web-services java logging audit veracode


    【解决方案1】:

    消息需要针对其所在的上下文进行转义。ESAPI 记录器确实会替换 \r\n 字符以及为 html 进行编码(如果配置为这样做)。

    目前这段代码给了我一个来自 Veracode 的 CWE 117:

    log.log(Level.WARNING, System.getenv("unsafe"));
    

    这段代码没有:

    log.log(Level.WARNING, ESAPI.encoder().encodeForHTML(System.getenv("unsafe")));
    

    encodeForHTML 将 \r\n 分别编码为 
,但下划线更简洁,如果您解码 html,您可能会得到意想不到的新行。

    【讨论】:

    • 您知道是否有替代 ESAPI 以通过 Veracode 的 CWE 117 测试?
    • 我自己没有使用过任何其他产品,但您可以在以下 Veracode 帮助中心页面查看已获批准的清洁剂的完整列表:Supported Cleansing Functions
    • @SorinPenteleiciuc 或者您可以使用 StringEscapeUtils.escapeJava(message) 方法。我能够通过 CWE-177 和 2.6 的 commons-lang mvnrepository.com/artifact/commons-lang/commons-lang/2.6
    【解决方案2】:

    如果你不想直接使用 ESAPI,你可以编写自己的函数来做类似的事情:

    • 转义换行并
    • 对 html 进行编码。

    我在这里给出了一个这样的函数示例(基于 ESAPI)作为答案:security flaw - veracode report - crlf injection

    【讨论】:

      【解决方案3】:

      我们可以。

      message.replaceAll("\r", "_").replaceAll("\n", "_");
      

      ESAPI.encoder().encodeForHTML(message);
      

      HtmlUtils.htmlEscape(input)
      

      【讨论】:

        【解决方案4】:

        您可以使用 StringEscapeUtilsescapeJava 方法在 Veracode 中传递 CWE-117。我能够通过 CWE-177 和 2.6 的 commons-lang https://mvnrepository.com/artifact/commons-lang/commons-lang/2.6

        StringEscapeUtils.escapeJava(message)
        

        【讨论】:

          猜你喜欢
          • 2017-12-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-04-11
          • 2013-09-22
          • 1970-01-01
          • 1970-01-01
          • 2013-01-16
          相关资源
          最近更新 更多