Return HTTP 400 for firewall-rejected requests instead of logging ERROR#47
Open
filipesantana18 wants to merge 2 commits into
Open
Return HTTP 400 for firewall-rejected requests instead of logging ERROR#47filipesantana18 wants to merge 2 commits into
filipesantana18 wants to merge 2 commits into
Conversation
Added a custom RequestRejectedHandler to return HTTP 400 for malicious requests.
Add test to verify firewall rejects malicious requests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Automated scanners frequently send malformed request paths (containing
;, encodedslashes,
.env,.git/config, etc.). Spring Security'sStrictHttpFirewallcorrectlyrejects these with a
RequestRejectedException. However, the defaultDefaultRequestRejectedHandlerrethrows the exception, so it propagates up toTomcat's
ErrorReportValveand is logged at ERROR with a full stack trace.In deployments where a log/SMTP appender is bound at ERROR level, this produces alert
spam for expected, correctly-blocked traffic.
Current behavior (log)
A malicious scanner request results in the following ERROR being logged:
Change
Register a
RequestRejectedHandlerbean using the built-inHttpStatusRequestRejectedHandler, so firewall rejections return a clean400 Bad Requestwithout an ERROR-level log or stack trace.The bean is auto-detected and wired into the
FilterChainProxyby Spring Security'sWebSecurityConfiguration(Spring Security 6.4.x / Spring Boot 3.4.4).Why this is safe
StrictHttpFirewallprotection is unchanged — malicious requests are stillrejected exactly as before.
400instead of apropagated exception logged as ERROR.
Tests
VootControllerTest.testFirewallRejectsMaliciousRequest()which sends a requestwith a malicious path (
/me/groups;malicious=probe) and asserts a400response. Thefirewall blocks the request before authentication, so no token is required.
Verification
Before: firewall rejections logged at ERROR with a full
RequestRejectedExceptionstack trace (see log above), and — where configured — triggered alert emails.
After: the same requests return
400with no ERROR log.