Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,10 @@ public Saml2LogoutValidatorResult validate(Saml2LogoutRequestValidatorParameters
if (parameters != null
&& parameters.getLogoutRequest().getBinding() == Saml2MessageBinding.REDIRECT
&& parameters.getLogoutRequest().getParameters().get(Saml2ParameterNames.SIG_ALG) == null) {
// Signature present without SigAlg is malformed — reject rather than bypass.
if (parameters.getLogoutRequest().getParameters().get(Saml2ParameterNames.SIGNATURE) != null) {
return Saml2LogoutValidatorResult.withErrors(new Saml2Error(
Saml2ErrorCodes.INVALID_SIGNATURE, "Signature present without SigAlg")).build();
}
return SamlUnsignedMessageValidator.validateLogoutRequest(
parameters.getLogoutRequest().getSamlRequest(),
parameters.getLogoutRequest().getBinding(),
parameters.getRelyingPartyRegistration());
return Saml2LogoutValidatorResult.withErrors(new Saml2Error(
Saml2ErrorCodes.INVALID_SIGNATURE, "Missing signature")).build();
}

Saml2LogoutValidatorResult result = delegate.validate(parameters);
if (!result.hasErrors()) {
return result;
}

Collection<Saml2Error> errors = result.getErrors().stream()
.filter(error -> !error.getDescription().contains("signature"))
.toList();
return Saml2LogoutValidatorResult.withErrors().errors(c -> c.addAll(errors)).build();
return delegate.validate(parameters);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,6 @@ void validatePassesThruSuccess() {
assertThat(validator.validate(parameters).hasErrors()).isFalse();
}

@Test
void validateRemovesMissingSignatureError() {
Saml2Error signatureError = new Saml2Error(Saml2ErrorCodes.INVALID_SIGNATURE, "Missing signature for object");
when(delegate.validate(any())).thenReturn(Saml2LogoutValidatorResult.withErrors(signatureError).build());
assertThat(validator.validate(parameters).hasErrors()).isFalse();
}

@Test
void validateDifferentErrorIsPassedThru() {
Saml2Error otherError = new Saml2Error(Saml2ErrorCodes.INVALID_SIGNATURE, "Failed to match issuer to configured issuer");
Expand All @@ -77,34 +70,16 @@ void validateDifferentErrorIsPassedThru() {
}

@Test
void unsignedRedirectRequestBypassesDelegateAndValidatesIssuerAndDestination() {
String destination = "http://sp.example.com/saml/SingleLogout";
String issuer = "http://idp.example.com";
String xml = """
<samlp:LogoutRequest
xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
Destination="%s">
<saml:Issuer>%s</saml:Issuer>
<saml:NameID>user@example.com</saml:NameID>
</samlp:LogoutRequest>
""".formatted(destination, issuer);

void unsignedRedirectRequestIsRejected() {
when(logoutRequest.getBinding()).thenReturn(Saml2MessageBinding.REDIRECT);
when(logoutRequest.getParameters()).thenReturn(Collections.emptyMap()); // no SigAlg
when(logoutRequest.getSamlRequest()).thenReturn(Saml2Utils.samlEncode(Saml2Utils.samlDeflate(xml)));

AssertingPartyMetadata party = mock(AssertingPartyMetadata.class);
when(party.getEntityId()).thenReturn(issuer);
RelyingPartyRegistration reg = mock(RelyingPartyRegistration.class);
when(reg.getAssertingPartyMetadata()).thenReturn(party);
when(reg.getSingleLogoutServiceLocation()).thenReturn(destination);
when(parameters.getRelyingPartyRegistration()).thenReturn(reg);

Saml2LogoutValidatorResult result = validator.validate(parameters);

assertThat(result.hasErrors()).isFalse();
verify(delegate, never()).validate(any());

assertThat(result.hasErrors()).isTrue();
assertThat(result.getErrors()).hasSize(1);
assertThat(result.getErrors().iterator().next().getDescription()).isEqualTo("Missing signature");
}
Comment on lines +80 to 83

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,9 @@ void idpInitiatedLogout() {
// UAA should redirect to the welcome page
new SamlWelcomePage(webDriver, samlServerConfig);

// UAA Should no longer be logged in
HomePage.assertThatGoHome_redirectsToLoginPage(webDriver, baseUrl);
// Unsigned SLO request from simpleSAMLphp should be rejected, leaving user logged in
webDriver.get(baseUrl + "/home");
new HomePage(webDriver, baseUrl);
}

@Test
Expand Down
Loading