I have an API in Spring Boot. In the controller layer, any POST that has a custom object annotated with @RequestBody flags Snyk security findings in the security pipeline.
For example:
public ResponseEntity<CustomObject> getCustomObject(@RequestBody CustomRequest customRequest) {
// code
}
The security report would show:
✗ [Low] Spring Cross-Site Request Forgery (CSRF)
Controller: Line 10
Info: The request parameter is vulnerable to Cross Site Request Forgery (CSRF) attacks due to not using Spring Security. This could allow an attacker to execute requests on a user's behalf. Consider including Spring Security's CSRF protection within your application.
If I remove the @RequestBody, the security report doesn't flag it anymore.
I have tried other validations such as @Valid and @Validated, as well as field value annotations on the object, but nothing works. I am wondering if there is a way around this without having to write a custom deserializer instead of using @RequestBody or adding it as a false positive.