File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88import org .springframework .security .config .annotation .web .configuration .EnableWebSecurity ;
99import org .springframework .security .config .http .SessionCreationPolicy ;
1010import org .springframework .security .web .SecurityFilterChain ;
11+ import org .springframework .security .web .firewall .HttpStatusRequestRejectedHandler ;
12+ import org .springframework .security .web .firewall .RequestRejectedHandler ;
1113import org .springframework .web .method .support .HandlerMethodArgumentResolver ;
1214import org .springframework .web .servlet .config .annotation .WebMvcConfigurer ;
1315
@@ -48,6 +50,14 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
4850 return http .build ();
4951 }
5052
53+ @ Bean
54+ public RequestRejectedHandler requestRejectedHandler () {
55+ // Return HTTP 400 for malicious/malformed requests (scanner probes with ;, encoded slashes, etc.)
56+ // instead of propagating RequestRejectedException up to Tomcat as ERROR.
57+ // StrictHttpFirewall correctly rejects these - we just want clean 400 responses without error logs/emails.
58+ return new HttpStatusRequestRejectedHandler ();
59+ }
60+
5161 @ Override
5262 public void addArgumentResolvers (List <HandlerMethodArgumentResolver > argumentResolvers ) {
5363 argumentResolvers .add (new UserHandlerMethodArgumentResolver ());
Original file line number Diff line number Diff line change @@ -237,4 +237,17 @@ void testAllGroups403() throws IOException {
237237 .statusCode (403 );
238238 }
239239
240+ @ Test
241+ void testFirewallRejectsMaliciousRequest () {
242+ // Verify that StrictHttpFirewall rejects malicious scanner requests (semicolons, encoded slashes, etc.)
243+ // with HTTP 400 via RequestRejectedHandler, WITHOUT reaching authentication or logging ERROR.
244+ // The firewall blocks the request before any auth processing, so no token is needed.
245+ given ()
246+ .when ()
247+ .accept (ContentType .JSON )
248+ .get ("/me/groups;malicious=probe" )
249+ .then ()
250+ .statusCode (400 );
251+ }
252+
240253}
You can’t perform that action at this time.
0 commit comments