Spring Security - Rejected Request
org.springframework.security.web.firewall.RequestRejectedException:
The request was rejected because the URL contained a potentially malicious String "//"
μμ²μ΄ κ±°λΆλλ μ΄μ
μΌλ°μ μΌλ‘ μ€νλ§ λΆνΈ κΈ°λ°μ μ ν리μΌμ΄μ μμ μ€νλ§ μν리ν°λ₯Ό μ¬μ©νλ€λ©΄ κΈ°λ³Έμ μΌλ‘ μ μ©λλ HttpFirewall ꡬν체μ μν΄ μ°μλλ μ¬λμ λ¬Έμλ₯Ό νμ©νμ§ μλλ‘ λμ΄μλ€. REST APIλ‘ λμμΈνλ κ²½μ° PathVariable λ‘ κ²½λ‘ μμ 리μμ€ μμ΄λλ₯Ό κ²μ¦νλ κ²½μ°κ° λλΆλΆμ΄λ€. λ°λΌμ, λλΆλΆμ κ²½μ° URL κ²½λ‘ μ μ°μλ μ¬λμ λ¬Έμλ μλ² μ μ₯μμ μλͺ»λ μμ²μ ν΄λΉλλ€.
@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
return webSecurity -> webSecurity.httpFirewall(httpFirewall())
.ignoring().requestMatchers("/error");
}
@Bean
public HttpFirewall httpFirewall() {
// NOTE: Spring Security provides DefaultHttpFirewall and StrictHttpFirewall.
StrictHttpFirewall httpFirewall = new StrictHttpFirewall();
httpFirewall.setAllowSemicolon(false);
httpFirewall.setAllowNull(false);
httpFirewall.setAllowBackSlash(false);
httpFirewall.setAllowUrlEncodedDoubleSlash(false);
List<String> allowedHttpMethods = Stream.of(
HttpMethod.GET,
HttpMethod.POST,
HttpMethod.PUT,
HttpMethod.DELETE,
HttpMethod.OPTIONS)
.map(HttpMethod::name)
.toList();
httpFirewall.setAllowedHttpMethods(allowedHttpMethods);
return httpFirewall;
}
κ±°λΆλ μμ²μ 무μνμ§ λ§κ³ μΆμ νμΈμ
μ¬λ°λ₯Έ ν΄λΌμ΄μΈνΈκ° μλ λ΄μ μν μλͺ»λ μμ²μΌ μ μμΌλ νλ‘ νΈμλ κ°λ°μκ° μλ²μμ μꡬνλ REST API μ€κ³λλ‘ μμ²νμ§ μμμ κ°λ₯μ±μ κ°κ³Όν΄μλ μλλ€. μλ²μμλ μ΅μν μ΄λ¬ν μμ²μ λν΄μ μ€λ₯ λ©μμ§ λλ Sentryμ κ°μ μ€λ₯ μΆμ μ루μ μΌλ‘ λΆμν μ μλλ‘ λ¨κ²¨μΌνλ€.
λ§μ½, AWS WAFλ₯Ό μ¬μ©νλ€λ©΄ μ€μ κ³Ό κ·μΉμ λ°λΌ λλΈ μ¬λμκ° ν¬ν¨λ μμ²μ΄ μλ² μ ν리μΌμ΄μ κΉμ§ λλ¬νμ§ μμ μ μμμ λ°±μλ κ°λ°μλ μκ³ μμ΄μΌ ν©λλ€.