발생
Spring Security 관련 코드 리팩토링 중에 실행하니 다음과 같은 에러가 발생하였다.
원인
원인에 대한 로그는 아래와 같다.
This method cannot decide whether these patterns are Spring MVC patterns or not. If this endpoint is a Spring MVC endpoint, please use requestMatchers(MvcRequestMatcher); otherwise, please use requestMatchers(AntPathRequestMatcher).
파파고 번역에 요청하면....(영어 쥐약...)
이 메서드는 이러한 패턴이 Spring MVC 패턴인지 여부를 결정할 수 없습니다.
이 EndPoint가 Spring MVC EndPoint인 경우 requestMatchers(MvcRequestMatcher)를 사용하고,
그렇지 않은 경우 requestMatchers(AntPathRequestMatcher)를 사용하십시오.
이미 해결책을 로그에서 알려주긴 했지만... 조금 더 살펴보도록 합시다.
현재 내가 작업중인 버전은 다음과 같은데,
id 'java' #17
id 'org.springframework.boot' version '3.1.2'
id 'io.spring.dependency-management' version '1.1.2'
dependencies {
...
/* Security & OAuth2.0 */
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client:3.1.2'
implementation 'org.springframework.boot:spring-boot-starter-security:3.1.2'
...
}
'최근에 새로 프로젝트를 만들고 진행해서 Security 버전 문제인가 했는데' 같은 문제가 발생하였고,
다른 부분을 찾으니
'springfamework.boot' 와 'dependency-management' 버전이 달랐다.
해결
현재 작업중인 버전을 다운그레이드 하면 실행이 된다...
하지만 앞으로도 동일한 문제를 마주할 수 있으니 해당 문제에 대해서 찾아보았다.
해당 문제가 발생하는 이유에 대한 내용은 Spring.io에 나와 있는데
CVE-2023-34035: Authorization rules can be misconfigured when using multiple servlets
CVE-2023-34035: Authorization rules can be misconfigured when using multiple servlets HIGH | JULY 17, 2023 | CVE-2023-34035 Description Severity is high unless otherwise noted. Spring Security versions 5.8 prior to 5.8.5, 6.0 prior to 6.0.5 and 6.1 prior t
spring.io
대강 요약하자면, 둘 이상의 서블릿을 사용중일때 보호하는 엔드포인트에 오류가 발생할 수 있다는 것이다.
내가 작성한 코드를 보면 .requestMathers("string-path").permitAll() 식으로 작성이 되어있는데,
.requestMathers(new AntPathRequestMatcher("string-path")).permitAll() 로 바꾸게 되면 정상 적으로 실행이 된다.
정상적으로 실행되는 이유는 AntPathRequestMatcher 클래스 중반부 설명을 보면 되는데,
해당 패턴과 일치하는 모든 Http Request 를 처리하기 때문에
위에서 문제가 되었던 여러 서블릿을 사용할 경우의 문제가 해결 된다.
물론 위에 해결 방법처럼 AntPathRequestMathcer 로 바꾸는 것이 아닌,
해당 문제가 발생하지 않는 버전으로 바꾸는것도 괜찮다. (만약 하나의 서블릿만 활용하고 있다면!)
아래를 보면,
Spring.io 에서 바꿨을때 문제가 있는지 없는지에 대한 판단을 정의해주었다.
마무리
버전을 수정할지,
코드를 수정할지는 각자 환경과 판단에 맞게 변경하면 되겠다.
아래 인프런 질문&답변 링크에 AntPathRequestMatcher 에 대한 설명이 괜찮아서 추가로 달아두었으니 참고하면 좋을 것 같다.
참고자료
https://spring.io/security/cve-2023-34035
CVE-2023-34035: Authorization rules can be misconfigured when using multiple servlets
CVE-2023-34035: Authorization rules can be misconfigured when using multiple servlets HIGH | JULY 17, 2023 | CVE-2023-34035 Description Severity is high unless otherwise noted. Spring Security versions 5.8 prior to 5.8.5, 6.0 prior to 6.0.5 and 6.1 prior t
spring.io
https://www.inflearn.com/questions/35701/%EC%A7%88%EB%AC%B8%EC%9E%85%EB%8B%88%EB%8B%A4
질문입니다 - 인프런 | 질문 & 답변
1.RequestMatcher matcher = entry.getKey();if (matcher.matches(request)) ~해당 부분이 어떤 흐름인지는 대충알겠는데확실하게 하고 싶어서요RequestMap에 담긴 key값과FiltetInvocation의 요청정보를 m...
www.inflearn.com
'DEV > ErorrBox' 카테고리의 다른 글
[Error] Git E325 Error (0) | 2024.03.23 |
---|---|
[Error] @SpringBootTest is not import (0) | 2023.12.07 |
[Error] org.openqa.selenium.ElementNotInteractableException: element not interactable (1) | 2023.05.28 |
[Error] @EqualsAndHashCode(callSuper=false) (0) | 2023.05.07 |
[Error] LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. (0) | 2023.04.30 |