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 issonarqube
expects 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
sonarqube
checksproperly setup logging subsystem, using one of the following ways:
take advantage of
output encoding
inlogback
- for example, write all logs in JSON:use
security-logging-logback
library, here is an example of correspondinglogback
configuration