Verify SAML assertion signature before trusting it

fix(auth): verify SAML assertion signature before trusting it
Verify SAML assertion signature before trusting it705edb-fix-verify-saml-assertion-signature-before-trusting-cve-2026-102894fixverify saml assertion signature before trusting

Committed by gitlawr

commit message
fix(auth): verify SAML assertion signature before trusting it

The SAML callback used to parse the incoming SAMLResponse XML by hand
(``etree.fromstring`` → ``root.find(NameID)`` / ``xpath(Attribute)``)
and pass the extracted values straight into user resolve / create +
JWT minting — with no signature verification. ``init_saml_auth`` (the
one path where the OneLogin toolkit is wired with ``strict=True`` and
the IdP cert) was only used for ``saml_login`` / ``saml_logout_callback``;
the callback that actually admits users never invoked ``process_response``.
 
That meant an unauthenticated remote attacker could POST a hand-crafted
``SAMLResponse`` to ``/auth/saml/callback`` and:
  * log in as any existing SAML-source user (attacker picks the NameID),
  * or provision a brand-new SAML-source user with the name of their
    choice and log in as it.
 
The ``_resolve_external_user`` source-mismatch check blocked cross-
provider impersonation (SAML → OIDC with the same name is refused
with 409) but not same-provider forgery.
 
Fix: route the response through ``OneLogin_Saml2_Auth.process_response()``,
gate on ``get_errors()`` being empty AND ``is_authenticated()``, and
only then read ``get_nameid()`` / ``get_attributes()``. Both HTTP-POST
and HTTP-Redirect (b64+DEFLATE) inputs are normalised to plain base64
before the toolkit sees them, since ``process_response`` only reads
``request_data['post_data']['SAMLResponse']``.
 
Signature floor: **at least one** of ``wantAssertionsSigned`` /
``wantMessagesSigned`` must be True. The toolkit ships with both
defaulted to False and ``strict=True`` alone is not enough to reject
unsigned assertions — leaving them both operator-configurable would
keep the vulnerability alive. Some IdPs sign only the outer
``<Response>`` and others only the inner ``<Assertion>``, so we don't
force one specific direction; if the operator has opted in to either,
respect that. If the operator sets neither (or tries to disable both
via ``--saml-security``), the helper snaps ``wantAssertionsSigned=True``
back on as the safe default.
 
Manual ``etree`` parsing is gone from the callback; the toolkit's own
XML parser is XXE-safe by default, so the ``resolve_entities=False``
guard we added earlier is no longer needed at this level.
``init_saml_auth`` is retained (still used by ``saml_login`` /
``saml_logout_callback``) but now shares the ``_saml_settings`` helper.
 
Regression notes for operators upgrading a live deployment:
  * ``saml_idp_x509_cert`` is now actually used to verify signatures.
    Deployments running with a misconfigured cert had been silently
    accepting anything; they need a correct cert now.
  * ``saml_sp_entity_id`` is now checked against the Assertion's
    ``<AudienceRestriction><Audience>``.
  * ``Destination`` on the response is now validated against the
    request's current URL; reverse-proxy setups need the Host header
    to reflect ``saml_sp_acs_url``.
  * IdPs that emit unsigned assertions (rare) will now be rejected.
 
Tests cover: (1) ``_saml_settings`` snaps the signature floor on
when neither knob is set; (2) it respects operator-configured
"Response-only" and "Assertion-only" combinations; (3) the callback
raises on non-empty toolkit errors (signature failure path); (4) the
callback raises when ``is_authenticated`` is False (status non-Success);
(5) the pinned-attribute-missing path still fails loudly with the
attribute name.

Editor assessment

This commit patches CVE-2026-102894. Exemplary. The body reconstructs the whole flaw: the SAML callback hand-parsed the response with etree and pushed NameID and attributes straight into user resolution and JWT minting, while the toolkit's strict validation was wired only to other endpoints. It states the consequences - log in as any existing SAML user, or provision a new one under a chosen name - and then the fix: route through process_response, gate on get_errors and is_authenticated, and enforce a signature floor. Operator regression notes and five tests complete it.

Browse categories

More fix examples · Back to search