RG123 (Community Member) asked a question.

Get CWE-117 - Improper Output Neutralization for Logs but input format has been validated

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


  • Anthony Fielding (Veracode)

    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

    Expand Post

Topics (1)

No articles found
Loading

Ask the Community

Get answers, share a use case, discuss your favorite features, or get input from the community.