Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAML: Process only verified signed data #30420

Merged
merged 2 commits into from
May 10, 2018
Merged
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 @@ -87,6 +87,14 @@ private SamlAttributes authenticateResponse(Element element, Collection<String>
if (logger.isTraceEnabled()) {
logger.trace(SamlUtils.describeSamlObject(response));
}
final boolean requireSignedAssertions;
if (response.isSigned()) {
validateSignature(response.getSignature());
requireSignedAssertions = false;
} else {
requireSignedAssertions = true;
}

if (Strings.hasText(response.getInResponseTo()) && allowedSamlRequestIds.contains(response.getInResponseTo()) == false) {
logger.debug("The SAML Response with ID {} is unsolicited. A user might have used a stale URL or the Identity Provider " +
"incorrectly populates the InResponseTo attribute", response.getID());
Expand All @@ -102,10 +110,10 @@ private SamlAttributes authenticateResponse(Element element, Collection<String>
throw samlException("SAML Response is not a 'success' response: Code={} Message={} Detail={}",
status.getStatusCode().getValue(), getMessage(status), getDetail(status));
}

checkIssuer(response.getIssuer(), response);
checkResponseDestination(response);

Tuple<Assertion, List<Attribute>> details = extractDetails(response, allowedSamlRequestIds);
Tuple<Assertion, List<Attribute>> details = extractDetails(response, allowedSamlRequestIds, requireSignedAssertions);
final Assertion assertion = details.v1();
final SamlNameId nameId = SamlNameId.forSubject(assertion.getSubject());
final String session = getSessionIndex(assertion);
Expand Down Expand Up @@ -156,17 +164,8 @@ private void checkResponseDestination(Response response) {
}
}

private Tuple<Assertion, List<Attribute>> extractDetails(Response response, Collection<String> allowedSamlRequestIds) {
final boolean requireSignedAssertions;
if (response.isSigned()) {
validateSignature(response.getSignature());
requireSignedAssertions = false;
} else {
requireSignedAssertions = true;
}

checkIssuer(response.getIssuer(), response);

private Tuple<Assertion, List<Attribute>> extractDetails(Response response, Collection<String> allowedSamlRequestIds,
boolean requireSignedAssertions) {
final int assertionCount = response.getAssertions().size() + response.getEncryptedAssertions().size();
if (assertionCount > 1) {
throw samlException("Expecting only 1 assertion, but response contains multiple (" + assertionCount + ")");
Expand Down Expand Up @@ -328,5 +327,4 @@ private void checkLifetimeRestrictions(Conditions conditions) {
private void checkLifetimeRestrictions(SubjectConfirmationData subjectConfirmationData) {
validateNotOnOrAfter(subjectConfirmationData.getNotOnOrAfter());
}

}