Skip to content

Conditions and AudienceRestriction validation #335

@mauromol

Description

@mauromol

An in-depth discussion is at #323.
This is somewhat related to #322, but it's more targeted at SAML specification compliancy.

The SAML 2.0 specification says:

  • section 3.4.1.4 of the Core specification, describing the processing rules of the Authentication Request Protocol:

The resulting assertion(s) MUST contain a <saml:AudienceRestriction> element
referencing the requester as an acceptable relying party. Other audiences MAY be included as
deemed appropriate by the identity provider.

  • section 4.1.4.2 of the Profiles specification, describing the Response usage in the Web SSO Profile:

The assertion(s) containing a bearer subject confirmation MUST contain an
<AudienceRestriction> including the service provider's unique identifier as an <Audience>

So, since the <AudienceRestriction> element appears within <Conditions>, although the <Conditions> element is optional in the schema, it should be present BECAUSE it should contain AT LEAST one AudienceRestriction matching the SP entity id.

What java-saml is doing right now is:

  • in com.onelogin.saml2.authn.SamlResponse.checkOneCondition() it checks that there is exactly one <Conditions> element; the javadoc says "checks that the samlp:Response/saml:Assertion/saml:Conditions element exists and is unique", but the latter part is useless because the schema already enforces that at most one such element is present; so, since that check is made after performing schema validation (at least if schema validation is enabled...), the check is partially useless
  • com.onelogin.saml2.authn.SamlResponse.validateAudiences() checks that, if any <AudienceRestriction> element exists, at least one of them is equal to the SP entity id

This said, considering what the specification requires, I think that the above two methods could be changed like this:

  • in com.onelogin.saml2.authn.SamlResponse.validateAudiences() make validation fail if validAudiences is empty
  • possibly remove com.onelogin.saml2.authn.SamlResponse.checkOneCondition(), because it becomes redundant by the above check, especially if it's moved at the same position of the checkOneCondition() call in com.onelogin.saml2.authn.SamlResponse.isValid(String)

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions