-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Description
This issue is related to #6638.
I use single OpenIDC IdP (google) from OAuth2Login Sample. Added a rest endpoint that use the same security configuration. When an ajax request to the rest endpoint with an expired JSESSIONID or no JESSIONID at all, the response is a redirect to google IdP. The redirect will be blocked by the browser since cross domain redirect is not allowed in CORS policy.
After tracing the code a little bit, and found the request matcher logic in OAuth2LoginConfigurer
might contribute to this behavior:
Line 450 in 5aacd0c
this.registerAuthenticationEntryPoint(http, this.getLoginEntryPoint(http, providerLoginPage)); |
Lines 619 to 634 in 5aacd0c
private AuthenticationEntryPoint getLoginEntryPoint(B http, String providerLoginPage) { | |
RequestMatcher loginPageMatcher = new AntPathRequestMatcher(this.getLoginPage()); | |
RequestMatcher faviconMatcher = new AntPathRequestMatcher("/favicon.ico"); | |
RequestMatcher defaultEntryPointMatcher = this.getAuthenticationEntryPointMatcher(http); | |
RequestMatcher defaultLoginPageMatcher = new AndRequestMatcher( | |
new OrRequestMatcher(loginPageMatcher, faviconMatcher), defaultEntryPointMatcher); | |
LinkedHashMap<RequestMatcher, AuthenticationEntryPoint> entryPoints = new LinkedHashMap<>(); | |
entryPoints.put(new NegatedRequestMatcher(defaultLoginPageMatcher), | |
new LoginUrlAuthenticationEntryPoint(providerLoginPage)); | |
DelegatingAuthenticationEntryPoint loginEntryPoint = new DelegatingAuthenticationEntryPoint(entryPoints); | |
loginEntryPoint.setDefaultEntryPoint(this.getAuthenticationEntryPoint()); | |
return loginEntryPoint; | |
} |
The defaultEntryPointMatcher
will filter out XMLHttpRequest. Should the entryPoints
be something like
entryPoints.put(new OrRequestMatcher(new NegatedRequestMatcher(defaultLoginPageMatcher), defaultEntryPointMatcher),
new LoginUrlAuthenticationEntryPoint(providerLoginPage));
Then the AJAX call to data will simply got 401 instead of a redirect, which the browser will block since it will be a cross domain redirect.
Originally posted by @simpleway in #6638 (comment)