仅使用replaceAll("\r", "_").replaceAll("\n", "_") 通过 Veracode CWE 117(日志的不正确输出中和)

Sor*_*iuc 3 java audit logging amazon-web-services veracode

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

 message.replaceAll("\r", "_").replaceAll("\n", "_");
Run Code Online (Sandbox Code Playgroud)

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

ESAPI.encoder().encodeForHTML(message);
Run Code Online (Sandbox Code Playgroud)

小智 5

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

StringEscapeUtils.escapeJava(message)
Run Code Online (Sandbox Code Playgroud)