You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Configure an invalid response URL at the identity provider (using nonconfigured registration id) a NullPointerException occurs during authentication process.
The Saml2WebSsoAuthenticationFilter does not check if the requested "RelyingParty" exits. If the RelyingPartyRegistrationRepository return null, processing not stopped.
java.lang.NullPointerException: null
at org.springframework.security.saml2.provider.service.servlet.filter.Saml2Utils.getServiceProviderEntityId(Saml2Utils.java:86) ~[spring-security-saml2-service-provider-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.security.saml2.provider.service.servlet.filter.Saml2WebSsoAuthenticationFilter.attemptAuthentication(Saml2WebSsoAuthenticationFilter.java:81) ~[spring-security-saml2-service-provider-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:212) ~[spring-security-web-5.2.1.RELEASE.jar:5.2.1.RELEASE]
[..]
Expected Behavior
no NPE :-)
Version
5.2.1.RELEASE
The text was updated successfully, but these errors were encountered:
It can be reproduce with a unit test or the SAML2 sample.
Unit Test
This test method (for Saml2WebSsoAuthenticationFilterTests) simulates the behavior. "CASE 2" throws the NullPointerException. The mocked RelyingPartyRegistrationRepository behaves the same as the implementation - if no entry exists, it returns null.
@Test
public void attemptAuthenticationWhenRegistrationIdExitsThenReturnAuthentication() {
AuthenticationManager authenticationManager = mock(AuthenticationManager.class);
given(authenticationManager.authenticate(any(Authentication.class))).willAnswer(a->a.getArgument(0));
given(repository.findByRegistrationId("idp-registration-id")).willReturn(mock(RelyingPartyRegistration.class));
filter = new Saml2WebSsoAuthenticationFilter(repository, "/some/other/path/{registrationId}");
filter.setAuthenticationManager(authenticationManager);
// CASE 1: registrationId exits
request.setPathInfo("/some/other/path/idp-registration-id");
request.setParameter("SAMLResponse", "response");
Assert.assertNotNull( filter.attemptAuthentication( request, response ) );
// CASE 2: registrationId not exits
request.setPathInfo("/some/other/path/notExits");
request.setParameter("SAMLResponse", "response");
Assert.assertNull( filter.attemptAuthentication( request, response ) );
}
Now I setup up Okta and make a small spelling mistake - instead of okta I wrote otak.
Launch Spring Boot application, open http://localhost:8080 and you will be caught in an endless loop. The app redirect to Okta, Okta redirect to the app (with the wrong registration id), the NPE occurs. App redirect to Okta, Okta redirect ...
Uh oh!
There was an error while loading. Please reload this page.
Summary
Configure an invalid response URL at the identity provider (using nonconfigured registration id) a NullPointerException occurs during authentication process.
E.g. registrationId is okta (at your service provider) but at the identity provider the configured response URL is http://mydomain/login/saml2/sso/anythingElse.
The Saml2WebSsoAuthenticationFilter does not check if the requested "RelyingParty" exits. If the RelyingPartyRegistrationRepository return null, processing not stopped.
Expected Behavior
no NPE :-)
Version
5.2.1.RELEASE
The text was updated successfully, but these errors were encountered: