REF-26: Validate the SAML signature profile before trusting an assertion signature - #93
Merged
thomasnymand merged 1 commit intoAug 26, 2026
Conversation
thomasnymand
force-pushed
the
feature/REF-26-assertion-signature-profile-validation
branch
2 times, most recently
from
August 13, 2026 11:26
68f07bd to
7efbea4
Compare
…ion signature validateSignature only called SignatureValidator.validate, a raw cryptographic check that the signature verifies against the IdP signing certificate from the configured metadata. It did not establish that the signature is bound to the assertion the SP goes on to consume, so a verifying signature was not on its own sufficient grounds for trusting the subject, attributes and NSIS level read from that assertion. Run SAMLSignatureProfileValidator before the cryptographic check. It requires exactly one reference, restricts the transforms to enveloped signature plus canonicalization, rejects Object children, and checks that the reference resolves to the element the signature is a child of, which is the binding that was missing. Trust is still anchored in the signing certificate from the configured IdP metadata. Also guard against a null signature up front: assertion.isSigned() was only checked at the end of validateAssertion and behind the profile validation flag, so an unsigned assertion reached SignatureValidator.validate(null, ...) and failed with an uncaught NullPointerException instead of a validation error. Signing is now enforced unconditionally in validateSignature, and that late, now unreachable check has been removed. Regression tests cover assertions where the signature reference does not resolve to the consumed element. They assert that the signature still verifies cryptographically, so they fail for the right reason and not because of a broken signature.
thomasnymand
force-pushed
the
feature/REF-26-assertion-signature-profile-validation
branch
from
August 13, 2026 11:30
7efbea4 to
2327f4f
Compare
mthiim
approved these changes
Aug 26, 2026
thomasnymand
deleted the
feature/REF-26-assertion-signature-profile-validation
branch
August 26, 2026 15:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Binds the assertion signature to the assertion the SP consumes.
Problem
AssertionValidationService.validateSignaturecalled onlySignatureValidator.validate(assertion.getSignature(), credential). That is a raw cryptographic check: it proves that some element in the document was signed with the IdP signing key from the configured metadata, but not that the signature covers the<Assertion>whose subject, attributes and NSIS level the SP then reads. A verifying signature was therefore not on its own sufficient grounds for trusting the identity data in the assertion, which is the core trust check of the authentication flow.Secondary issue in the same method:
assertion.getSignature()is null for an unsigned assertion, soSignatureValidator.validate(null, ...)threw an uncaughtNullPointerException(HTTP 500) instead of a validation error. Theassertion.isSigned()check that should have caught this ran at the end ofvalidateAssertion, and only whenoiosaml.servlet.profile.validation.enabledwas true.Changes
SAMLSignatureProfileValidatorbefore the cryptographic check. It requires exactly one reference, restricts the transforms to enveloped-signature plus canonicalization, rejectsObjectchildren, and checks that the reference resolves to the element the signature is a child of — the binding that was missing.validateSignaturenow rejects an unsigned assertion (!isSigned() || signature == null) with anAssertionValidationExceptionbefore touching it, so signing is enforced unconditionally instead of behind the profile-validation flag.isSigned()check at the end ofvalidateAssertion.Trust is still anchored where it was: the verification credential is the signing certificate from the configured IdP metadata, and an embedded
KeyInfois not trusted.Verification
Two regression tests in
AssertionValidationServiceTestcover assertions whose signature verifies but is not bound to the element being consumed, one where the consumed assertion has its own ID and one where it reuses the ID of the referenced element. Each test first asserts that the signature still verifies under a rawSignatureValidator.validate, so it cannot pass for the wrong reason, and then asserts that validation rejects the assertion.Checked in both directions: