How to fix Veracode CWE 117 (Improper Output Neutralization for Logs)

后端 未结 5 1628
遥遥无期
遥遥无期 2021-02-02 01:21

There is an Spring global @ExceptionHandler(Exception.class) method which logs exception like that:

@ExceptionHandler(Exception.class)
void handleEx         


        
5条回答
  •  野性不改
    2021-02-02 01:41

    I am new to Veracode and was facing CWE-117. I understood this error is raised by Veracode when your logger statement has the potential to get attacked via malicious request's parameter values passed in. So we need to removed /r and /n (CRLF) from variables that are getting used in the logger statement.

    Most of the newbie will wonder what method should be used to remove CRLF from variable passed in logger statement. Also sometime replaceAll() will not work as it is not an approved method by Veracode. Therefore, here is the link to approved methods by Veracode to handles CWE problems. https://help.veracode.com/reader/4EKhlLSMHm5jC8P8j3XccQ/IiF_rOE79ANbwnZwreSPGA

    In my case I have used org.springframework.web.util.HtmlUtils.htmlEscape mentioned in the above link and it resolved the problem.

    private static final Logger LOG = LoggerFactory.getLogger(MemberController.class);
    //problematic logger statement 
    LOG.info("brand {}, country {}",brand,country);
    //Correct logger statement
    LOG.info("brand {}, country {}",org.springframework.web.util.HtmlUtils.htmlEscape(brand),org.springframework.web.util.HtmlUtils.htmlEscape(country));
    

提交回复
热议问题