SAML-Toolkits / java-saml

Java SAML toolkit
MIT License
633 stars 395 forks source link

Conditions and AudienceRestriction validation #335

Open mauromol opened 3 years ago

mauromol commented 3 years ago

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:

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.

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:

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

What do you think?

pitbulk commented 3 years ago

We could agree on making the AudienceRestriction element required, but that gonna be a behavior change, so maybe we need to control it with a security setting

checkOneCondition is covered by the schema validator, but I don't see such extra check something bad.

pitbulk commented 3 years ago

@mauromol Do you have a PR for this one?

mauromol commented 3 years ago

No, because I still have some doubts. First of all, is a dedicated security setting for this really worth? Considering that:

So, I would be inclined to implement this without any further "flag" to enable it. Or, on the contrary, to add a flag to disable it to explicitly preserve backward compatibility (or to go even further, as requested in #322: what do you think about it?), however I was wondering whether it's worth the effort.

With regards to checkOneCondition: yes, it does not hurt, but then I'm a bit lost on the policy: in https://github.com/onelogin/java-saml/issues/334#issuecomment-885921926 you substantially say that schema validation is enough, but here you'd prefer to maintain the redundant check: so what should be the way? :-)

mauromol commented 3 years ago

@pitbulk what do you then think about this? I can add the additional check to AudienceRestriction element, but I need to know if you wish it to be an opt-in or an opt-out (when "isStrict" is set in both cases). WRT checkOneCondition, again I'm open to both decisions: remove the (redundant and useless) check or leave it there (for whatever reason).