Skip to content

Commit e233adf

Browse files
authored
Merge pull request #47 from filipesantana18/main
Return HTTP 400 for firewall-rejected requests instead of logging ERROR
2 parents 89d4a78 + 0b22a7f commit e233adf

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

‎src/main/java/voot/security/SecurityConfig.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
99
import org.springframework.security.config.http.SessionCreationPolicy;
1010
import org.springframework.security.web.SecurityFilterChain;
11+
import org.springframework.security.web.firewall.HttpStatusRequestRejectedHandler;
12+
import org.springframework.security.web.firewall.RequestRejectedHandler;
1113
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
1214
import 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());

‎src/test/java/voot/VootControllerTest.java‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)