diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/saml/SamlAuthenticator.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/saml/SamlAuthenticator.java
index f8826bebcac71..61e451150cd08 100644
--- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/saml/SamlAuthenticator.java
+++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/saml/SamlAuthenticator.java
@@ -159,8 +159,10 @@ private String getSessionIndex(Assertion assertion) {
private void checkResponseDestination(Response response) {
final String asc = getSpConfiguration().getAscUrl();
if (asc.equals(response.getDestination()) == false) {
- throw samlException("SAML response " + response.getID() + " is for destination " + response.getDestination()
+ if (response.isSigned() || Strings.hasText(response.getDestination())) {
+ throw samlException("SAML response " + response.getID() + " is for destination " + response.getDestination()
+ " but this realm uses " + asc);
+ }
}
}
diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlAuthenticatorTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlAuthenticatorTests.java
index 8bb9890151ff0..913258cf45c5d 100644
--- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlAuthenticatorTests.java
+++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlAuthenticatorTests.java
@@ -523,13 +523,59 @@ public void testIncorrectDestinationIsRejected() throws Exception {
"" +
"" +
"";
- SamlToken token = token(signDoc(xml));
+ SamlToken token = randomBoolean() ? token(signDoc(xml)) : token(signAssertions(xml, idpSigningCertificatePair));
final ElasticsearchSecurityException exception = expectSamlException(() -> authenticator.authenticate(token));
assertThat(exception.getMessage(), containsString("destination"));
assertThat(exception.getCause(), nullValue());
assertThat(SamlUtils.isSamlException(exception), is(true));
}
+ public void testMissingDestinationIsNotRejectedForNotSignedResponse() throws Exception {
+ Instant now = clock.instant();
+ Instant validUntil = now.plusSeconds(30);
+ String sessionindex = randomId();
+ final String xml = "\n" +
+ "" +
+ "" + IDP_ENTITY_ID + "" +
+ "" +
+ "" +
+ "" + IDP_ENTITY_ID + "" +
+ "" +
+ "randomopaquestring" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" + PASSWORD_AUTHN_CTX + "" +
+ "" +
+ "" +
+ "" +
+ "daredevil" +
+ "" +
+ "" +
+ "";
+ SamlToken token = token(signAssertions(xml, idpSigningCertificatePair));
+ final SamlAttributes attributes = authenticator.authenticate(token);
+ assertThat(attributes, notNullValue());
+ assertThat(attributes.attributes(), iterableWithSize(1));
+ final List uid = attributes.getAttributeValues("urn:oid:0.9.2342.19200300.100.1.1");
+ assertThat(uid, contains("daredevil"));
+ assertThat(uid, iterableWithSize(1));
+ assertThat(attributes.name(), notNullValue());
+ assertThat(attributes.name().format, equalTo(TRANSIENT));
+ }
+
public void testIncorrectRequestIdIsRejected() throws Exception {
Instant now = clock.instant();
Instant validUntil = now.plusSeconds(30);