
RG123 (Community Member) asked a question.
We are validating input via validation annotations in Spring MVC, to ensure the input only contains ceratin characters. However, we still get the CRLF Injection flaw when logging that value. Would this validation not prevent the CWE error.
An example validation is:
@Pattern(regexp = "^(?[a-zA-Z0-9-]{1,36})$")
thanks
.png)
Hi @RG123 (Community Member),
Thanks for your question.
Your allow-list regex-based validation would prevent log poisoning as it does not permit any carriage return or new line characters or their encoded variants. If you are going to use your own validation mechanism you will need to propose a mitigation. This is because Veracode does not know what would be an appropriate regex given the context. please be sure to state the validation used when proposing the mitigation to help the security team understand what mitigating controls are in place.
If you encode the data just before logging using a suitable supported cleansing function such as org.springframework.web.util.HtmlUtils.htmlEscape(), Veracode static analysis should detect the untrusted data has been cleansed and the flaw will be remediated and no longer show. You can find the list of supported cleansing functions here: https://help.veracode.com/reader/4EKhlLSMHm5jC8P8j3XccQ/IiF_rOE79ANbwnZwreSPGA.
Kind regards,
Anthony Fielding