我在一些论坛上读到了一个神话,即通过做这样的事情就足以通过Veracode CWE 117(日志的不正确输出中和)问题。 有人可以确认是否是这种情况吗?
message.replaceAll("\r", "_").replaceAll("\n", "_");
从这个主题How to fix Veracode CWE 117 (Improper Output Neutralization for Logs) ,我知道我需要做这样的事情
ESAPI.encoder().encodeForHTML(message);
答案 0 :(得分:2)
消息需要针对其所在的上下文进行转义.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,你可能会得到意想不到的新行。< / p>
答案 1 :(得分:1)
如果您不想直接使用ESAPI,您可以编写自己的函数来执行类似的操作:
我在这里给出了一个这样的函数的例子(基于ESAPI)作为答案:security flaw - veracode report - crlf injection
答案 2 :(得分:1)
我们可以选择任何一种方式。
message.replaceAll("\r", "_").replaceAll("\n", "_");
或
ESAPI.encoder().encodeForHTML(message);
或
HtmlUtils.htmlEscape(input)
答案 3 :(得分:1)
您可以使用 StringEscapeUtils 的 escapeJava 方法在 Veracode 中传递 CWE-117。我能够使用 2.6 的 commons-lang https://mvnrepository.com/artifact/commons-lang/commons-lang/2.6
通过 CWE-177StringEscapeUtils.escapeJava(message)