fix: read identity only from the signed assertion - #38
Draft
jarvis9443 wants to merge 1 commit into
Draft
Conversation
saml_verify_doc verifies one <Signature> and reports success, but the identity readers then select //samlp:Response/saml:Assertion across the whole document, so the assertion an identity is read from need not be the one the signature covered. That is signature wrapping: a Response carrying one genuinely signed assertion beside a forged one verifies, while a reader picks the forged assertion. Make identity come only from signed content, structurally: - Anchor the four identity readers to /samlp:Response/saml:Assertion, so identity is read only from an assertion that is a direct child of the verified root message, never from one nested in Extensions, Advice, or a non-Response wrapper such as ArtifactResponse. - After verification, confine_identity_to_signature drops every top-level assertion the verified signature does not cover: a whole-message signature covers all of them; an assertion-level signature covers only the one its Reference points to, so any other top-level assertion is unsigned and removed. The identity a reader returns is then always exactly what the IdP signed. Closes #34
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
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.
What
saml_verify_docverifies one<Signature>and reports success. The identity readers (doc_name_id,doc_attrs,doc_session_index,doc_session_expires) then run//samlp:Response/saml:Assertion/...over the whole document, so the assertion an identity is read from need not be the one the signature covered.That is signature wrapping: present a
Responsecarrying one genuinely IdP-signed assertion beside a forged one, and verification passes while the readers pick the forged assertion.Approach
Make identity come only from signed content, at the point it is read, instead of adding a separate check that re-derives what the readers can reach:
/samlp:Response/saml:Assertion(single leading slash). Identity can now only be read from an assertion that is a direct child of the verified root message — never from one nested inExtensions,Advice, or a wrapper such asArtifactResponse.confine_identity_to_signaturedrops every top-level assertion the verified signature does not cover. A whole-message signature (Reference resolves to the root) covers all of them; otherwise only the single assertion its Reference points to may remain, and any other top-level assertion is unsigned and removed. The removed nodes are siblings, so freeing one never dangles another.The identity a reader returns is then always exactly what the IdP signed, whatever else the document contains.
Why this shape
Response. A forged assertion smuggled through a non-Responsewrapper (e.g.ArtifactResponsewhose own status is Success) yields no identity, because the readers are anchored to aResponseroot (TEST 14).Adviceis trusted (TEST 11); a response padded with unrelated forged assertions still reads its genuinely signed identity instead of failing the login (TEST 8).Changes
src/saml.c.signed_reference_targetandconfine_identity_to_signatureinsrc/sig.c, wired intosaml_binding_post_verify.t/signed-response.t, 14 cases: assertion-level and response-level signatures, the forged-sibling / nested-Response/Advice/Extensions/ non-Response-root wrapping shapes, multi-assertion coverage, and aLogoutResponsestatus read.saml_doc_status_codeis unchanged and no new binding status is introduced.Testing
prove t/signed-response.t(self-contained, no IdP needed), plus the existing Keycloak end-to-end suite in CI. The tree mutation was checked for memory safety with valgrind (0 errors across the removal scenarios) and a repeated-request stress that serializes the whole tree after eachconfine_identity_to_signature.Relationship to #32
This is an alternative to #32 for the same vulnerability. #32 keeps the document-wide readers and adds
saml_verified_identity_is_signed, a check that mirrors the reader XPaths and only runs when the root local-name isResponse; this PR scopes the readers themselves, which is what #34 asked for and which also covers the non-Response-root case. Closes #34.Out of scope
Reference transform restrictions (SAML Core 5.4),
doc_issuerunder an assertion-level signature (#33),LogoutRequestidentity (#36), and assertionConditions(#37) — the same boundaries as #32.