I am getting this sonar issue(Security - Potential CRLF Injection for logs) while logging request body parameter in code.
public ResponseEntity<SomeDto> someMethod(@RequestBody User user) {
log.info("user received as --> {}", user);
}
How to resolve this issue? Thank you.
That is really annoying warning produced by
sonarqube. The problem issonarqubeexpects from you to write dumb code like:which is obviously unacceptable.
If your security team do believe CR/LF characters in logs is a real security problem the only correct approach is following:
disable corresponding
sonarqubechecksproperly setup logging subsystem, using one of the following ways:
take advantage of
output encodinginlogback- for example, write all logs in JSON:use
security-logging-logbacklibrary, here is an example of correspondinglogbackconfiguration