Skip to content

fix(security): cross-check SAML NameID namespace (GO-2026-6909) - #896

Merged
fclairamb merged 7 commits into
mainfrom
fix/security-saml-nameid
Nov 16, 2026
Merged

fclairamb merged 7 commits into
mainfrom
fix/security-saml-nameid

Conversation

@fclairamb

Copy link
Copy Markdown
Owner

What

Fixes finding 1 of the security review #892 — the reachable half of GO-2026-6909 (github.com/crewjam/[email protected], no fixed version published).

crewjam/saml's Subject uses the bare XML tag xml:"NameID", which matches a <NameID> element in any namespace. A signature-valid assertion that omits <saml:NameID> but carries a foreign-namespace <NameID> inside <saml:Subject> populates Subject.NameID.Value from the foreign element. SolidPing trusts that value: mapAssertion uses it as the provider link id and falls back to it as the account email, and findOrCreateUser links/creates accounts by email — so a spoofed NameID could reach an existing account (including ones that never used SAML).

(The advisory's other half — the nil-Issuer panic in validateAssertion — is not reachable as configured: spBase never sets ExpectedIDPEntityID. govulncheck will keep flagging the module until upstream ships a fix; this PR removes the reachable exposure.)

Fix

New validateNameIDNamespace, called in HandleACS right after ParseResponse:

  • Re-parses the raw POSTed SAMLResponse with struct tags spelling out the SAML assertion namespace (encoding/xml matches by namespace URI + local name, never by bare local name — verified against the attack shape).
  • Fail closed: the extracted NameID must equal a <NameID> in the SAML namespace of a visible plaintext assertion; a mismatch (including "no saml:NameID at all" vs a non-empty extracted value) is wrapped into ErrSAMLAssertionInvalid.
  • Skip what cannot be inspected: encrypted assertions, absent/undecodable/unparseable response — ParseResponse already validated signature/conditions/audience there; the guard adds no new rejection reasons for responses it cannot see into.
  • No behavior change for legitimate assertions (NameID→email fallback kept), no config flag, no wire change. SAML remains opt-in (default off).

Tests

New saml_nameid_test.go:

  • attack matrix: foreign-namespace NameID refused; matching saml:NameID passes; differing value refused; foreign NameID alongside the real one cannot substitute; multi-assertion response matches any; encrypted assertion skipped; nil Subject/NameID skipped.
  • fail-open contract: absent field, undecodable base64, non-XML payload → deferred to ParseResponse.
  • Positive control for the full flow: the existing TestSAMLHandleACS_HappyPath (real signed assertion from the in-repo fake IdP) still passes through the guard — the whole auth package suite is green.

go test ./internal/handlers/auth/ green (~60s), golangci-lint 0 issues, go build ./... OK.

Follow-up (not in this PR)

Track upstream for a fixed crewjam/saml; the nil-Issuer panic variant would become reachable if ExpectedIDPEntityID is ever set, so do that together with the upgrade.

Refs #892

crewjam/saml (through v0.6.3, no upstream fix) reads Subject.NameID with
the bare XML tag xml:"NameID", matching a <NameID> in ANY namespace. A
signature-valid assertion omitting <saml:NameID> but carrying a
foreign-namespace <NameID> inside <saml:Subject> populates
Subject.NameID.Value from the foreign element. mapAssertion trusts that
value (provider link id, email fallback) and findOrCreateUser links
accounts by email, so the spoofed NameID could reach another account.

After ParseResponse, re-parse the raw SAMLResponse namespace-aware and
require the extracted NameID to equal a <NameID> in the SAML assertion
namespace. Fail closed on a visible mismatch; skip what cannot be
inspected (encrypted assertions, absent/undecodable/unparseable
response), where ParseResponse remains the authority.

Refs #892 (finding 1)
@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.71%. Comparing base (1cad98a) to head (561d592).

Files with missing lines Patch % Lines
server/internal/handlers/auth/saml_service.go 94.73% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #896      +/-   ##
==========================================
- Coverage   90.73%   90.71%   -0.02%     
==========================================
  Files        1370     1370              
  Lines      140915   140934      +19     
==========================================
- Hits       127864   127854      -10     
- Misses      13042    13071      +29     
  Partials        9        9              
Files with missing lines Coverage Δ
server/internal/handlers/auth/saml_service.go 95.01% <94.73%> (-0.03%) ⬇️

... and 20 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

fclairamb and others added 6 commits November 16, 2026 01:15
… runner

The slow probes slept a fixed 1.2s, so on a loaded CI runner they finished
before the fast results landed and the ordering assertion failed. Sleep 6s so
the ordering holds regardless of runner speed.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@fclairamb
fclairamb merged commit df0d7b6 into main Nov 16, 2026
38 checks passed
@fclairamb
fclairamb deleted the fix/security-saml-nameid branch November 16, 2026 02:17
fclairamb added a commit that referenced this pull request Nov 16, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.51.0](v0.50.2...v0.51.0)
(2026-11-16)


### Features

* Pingdom check importer, insights period selector, job retry log levels
([#904](#904))
([7914164](7914164))


### Bug Fixes

* **security:** bound status page historyDays, mask config tokens in
replay, JS websocket redirect policy, docs JWT placeholders
([#903](#903))
([6b432e0](6b432e0))
* **security:** cap the pre-auth body buffer in ServiceSignature
([#894](#894))
([c4da4c5](c4da4c5)),
closes [#892](#892)
* **security:** cross-check SAML NameID namespace (GO-2026-6909)
([#896](#896))
([df0d7b6](df0d7b6))
* **security:** treat known dev JWT secrets as placeholders
([#895](#895))
([1cad98a](1cad98a)),
closes [#892](#892)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: Claude Sonnet 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant