Skip to content

feat: add an option to reject an assertion that has no Audience - #14

Merged
marevol merged 1 commit into
mainfrom
feat/reject-missing-audience
Nov 10, 2026
Merged

marevol merged 1 commit into
mainfrom
feat/reject-missing-audience

Conversation

@marevol

@marevol marevol commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Summary

SamlResponse.validateAudiences() rejects an Assertion only when it lists Audiences and none of them is the SP entity ID. An Assertion with no AudienceRestriction/Audience at all passes. The Web Browser SSO profile (SAML Profiles 4.1.4.2) requires a bearer Assertion to carry an AudienceRestriction that includes the SP, so a signed Assertion without one, issued for no particular SP, is accepted by every SP that trusts the IdP.

This adds an opt-in setting, modelled on rejectUnsolicitedResponsesWithInResponseTo:

  • Saml2Settings#setRejectMissingAudience(boolean) / isRejectMissingAudience()
  • property onelogin.saml2.security.reject_missing_audience (SettingsBuilder.SECURITY_REJECT_MISSING_AUDIENCE)
  • default false: behaviour is unchanged unless the option is turned on

When enabled, an Assertion with no Audience fails with ValidationException.WRONG_AUDIENCE (the same error as a non-matching Audience). An Audience that does not match the SP is rejected in both modes.

Tests

AuthnResponseTest (signed responses):

  • option off (default): a response with no Audience is accepted
  • option on: a response with no Audience is rejected with WRONG_AUDIENCE
  • option on: a response with the correct Audience is accepted
  • a non-matching Audience is rejected with the option off and on

SettingBuilderTest: the property key, default false, and true/false parsing.

mvn test: core 421, toolkit 92, all passing.

Docs

README and the sample properties list the new key; CLAUDE.md notes the default.

An Assertion that carries no AudienceRestriction/Audience passes
validateAudiences(): only an Assertion that lists Audiences without the SP
entity ID is rejected. The Web Browser SSO profile requires a bearer
Assertion to name the SP in an AudienceRestriction, so a signed Assertion
without one, issued for no particular SP, is accepted by every SP that
trusts the IdP.

Add Saml2Settings#setRejectMissingAudience (property
onelogin.saml2.security.reject_missing_audience). When true, an Assertion with
no Audience fails with ValidationException.WRONG_AUDIENCE, the same error as
an Audience that does not match. The default is false, so existing behaviour
is unchanged; an Assertion whose Audience does not match the SP is rejected
in both modes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant