Skip to content

feat(saml): add dedicated_scope option for SAML providers - #2893

Merged
hf merged 8 commits into
masterfrom
stojan/saml-dedicated-scope
Nov 6, 2026
Merged

hf merged 8 commits into
masterfrom
stojan/saml-dedicated-scope

Conversation

@hf

@hf hf commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Some SAML identity providers (famously Entra) don't allow the same entity ID to be registered with multiple "applications," making Supabase Auth usable only with one application. Some enterprise use-cases are therefore hard to build.

In this PR we add a dedicated_scope optional boolean on an SSO provider, which in SAML means that the provider can only be used via its own new Entity ID and URLs scoped to the provider's unique ID.

Dedicated scope Entity ID, Metadata URL ACS URL
False or Null /sso/saml/metadata /sso//saml/acs
True /sso/{uuid}/saml/metadata /sso/{uuid}/saml/acs

This way in Entra you can register many SPs served by the same Supabase Auth project by creating them with the dedicated_scope boolean.

Notes:

  • Adds a dedicated_scope boolean to SAML SSO providers. When set, that provider's ACS URL and SP metadata URL (and, by extension, the entity ID GoTrue presents to the IdP, which defaults to the metadata URL) are scoped to the provider's own ID, instead of using the URLs shared by every SAML provider in the project. The same signing key/certificate is still used.
  • Useful for IdPs that require a unique ACS URL/entity ID per connection, and isolates assertions issued for one connection from being replayed against another.
  • New dedicated routes GET /sso/{sso_provider_id}/saml/metadata and POST /sso/{sso_provider_id}/saml/acs alongside the existing shared /sso/saml/* endpoints; the ACS handler rejects a provider hitting the wrong endpoint for its scope setting.
  • dedicated_scope can be set on create/update via the admin SSO provider API and is documented in openapi.yaml.

Lets a SAML SSO provider opt into using its own provider ID as part of
its ACS URL and entity ID (which defaults to the SP metadata URL),
instead of the URLs shared by every SAML provider in the project. The
same signing key is still used. This is useful for IdPs that require a
unique ACS URL/entity ID per connection, and isolates assertions
issued for one connection from being replayed against another.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@hf
hf requested a review from a team as a code owner October 30, 2026 06:59
Comment thread internal/models/sso.go Resolved
hf and others added 2 commits October 30, 2026 08:10
The dedicated-scope guard in the ACS handler previously ran before
ParseResponse, using the SSO provider resolved from an unauthenticated
Issuer peeked out of the raw, unverified SAMLResponse XML in the
IdP-initiated flow. Move that guard to after the assertion has been
cryptographically validated, and require IdP-initiated requests on a
dedicated-scope endpoint to carry an explicit, matching Destination
rather than relying on the library's conditional check.

Also log a WARN with the old/new value whenever dedicated_scope is
toggled on an existing provider via the admin API, since it
immediately changes the ACS URL/entity ID that provider expects.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@hf

hf commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the security review findings on the dedicated_scope ACS/entity-ID scoping (fixed in 46c0560):

  • Scope-confusion bypass in IdP-initiated flow: the dedicated-scope guard now runs after ParseResponse succeeds (i.e. after cryptographic validation), instead of before it based on the unauthenticated Issuer peeked from the raw SAMLResponse XML. Also added a check that an IdP-initiated request hitting a dedicated-scope endpoint must carry an explicit Destination matching that endpoint's ACS URL, rather than relying on the library's conditional check.
  • No protection against toggling dedicated_scope on a live provider: the admin update handler now logs a WARN (with old/new value and provider ID) whenever dedicated_scope changes on an existing provider, since this immediately changes the ACS URL/entity ID that provider expects.
  • The informational note about the pre-validation XML peek of the untrusted SAMLResponse is pre-existing behavior (used to look up which provider's key to validate against) and unchanged by this PR.

hf and others added 2 commits November 4, 2026 11:45
dedicated_scope effectively changes the entity ID this SP presents to
the IdP (it defaults to the SP metadata URL, which becomes scoped to
the provider's ID when enabled), so toggling it after the IdP has been
configured would silently break the connection. Reject any attempt to
change it on an existing provider with a clear error instead.

Also move the column from sso_providers to saml_providers: it's a
SAML-protocol detail (alongside entity_id/metadata_url/name_id_format)
rather than provider-agnostic config like resource_id/disabled, and
it's now exposed nested under `saml` in the admin API response to
match.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Previously the explicit Destination check was only enforced on
dedicated-scope ACS endpoints. Generalize it to every IdP-initiated
response so the global, shared ACS endpoint doesn't implicitly accept
assertions meant for another endpoint, asserting the invariant
ourselves rather than relying solely on crewjam/saml's internal
Recipient check.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Destination is optional per the SAML spec and many real IdPs omit it,
especially for IdP-initiated flows. Only reject when an explicit
Destination is present and doesn't match this endpoint's ACS URL; an
absent Destination no longer blocks the flow.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
cemalkilic added a commit that referenced this pull request Nov 6, 2026
…2909)

## What

Adds `GO-2026-6909` to the `vulncheck-filter` ignore map so `make
vulncheck` passes again. It currently fails on every branch (e.g.
#2893).

## Why it's safe to ignore

[GO-2026-6909](https://pkg.go.dev/vuln/GO-2026-6909) affects
`github.com/crewjam/saml` through v0.5.1, and **there's no upstream
fix**. We're on v0.4.14, reached via `handleSamlAcs →
ServiceProvider.ParseResponse`.

The advisory covers two issues, and both need an assertion signed by an
IdP we already trust:

1. **Nil `assertion.Issuer` dereference** in `validateAssertion`. It
panics only after signature verification. The `recoverer` middleware
(`internal/api/api.go`) catches the panic, so the result is a 500 for
that one request, not a process crash.
2. **Namespace-blind `Subject.NameID`**. We read `NameID` in
`SAMLAssertion.SubjectID()` only when the `subject-id` attribute is
missing. Exploiting it would need the IdP itself to sign an assertion
that leaves out `<saml:NameID>` and includes a foreign-namespace
`<NameID>`. An attacker can't inject that element without breaking the
signature.

Remove this entry once crewjam/saml ships a fix.

## Verification

- `go test ./hack/vulncheck-filter` passes
- `govulncheck ./... | go run ./hack/vulncheck-filter` exits 0
@hf
hf merged commit bfbe078 into master Nov 6, 2026
10 checks passed
@hf
hf deleted the stojan/saml-dedicated-scope branch November 6, 2026 11:30
jclab-joseph added a commit to dilion-io/dilion that referenced this pull request Nov 10, 2026
Upstream supabase/auth#2893, documented in the openapi.yaml synced at
bfbe078. Some IdPs, notably Entra, allow only one application per SP
entity ID, so a project could connect to such an IdP only once.

A provider created with `dedicated_scope: true` gets SP URLs of its own:

  shared:     /sso/saml/metadata (entity ID), /sso/saml/acs
  dedicated:  /sso/{id}/saml/metadata,        /sso/{id}/saml/acs

The key pair is the same. The flag can be set on create only: changing it
would change the entity ID the IdP was configured with, so an update
carrying it is a 400 (migration 0123 adds the column).

- POST /sso builds the AuthnRequest with the provider's scope.
- /sso/{id}/saml/metadata answers only for a dedicated-scope provider.
- The ACS validates the assertion against the scope of the URL it was
  posted to. Only after validation does it require the provider to own
  that scope: a dedicated provider its own endpoint, any other the shared
  one. So an assertion validated for one connection cannot sign in
  through another.
- Like upstream, an IdP-initiated Response whose Destination names
  another ACS is refused before parsing.

The tests sign in on each endpoint. Each cross-scope assertion is signed
for the ACS it is posted to, so it validates, and must still be refused.
Removing the ownership check makes the first of them sign in.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cstockton pushed a commit that referenced this pull request Nov 16, 2026
🤖 I have created a release *beep* *boop*
---


##
[2.198.0](v2.197.0...v2.198.0)
(2026-11-13)


### Features

* clear existing password on recover
([#2887](#2887))
([a7e97d6](a7e97d6))
* **mfa:** add recovery codes unenroll guards
([#2787](#2787))
([4b5069b](4b5069b))
* min password length uses runes, not bytes
([#2879](#2879))
([d7955e9](d7955e9))
* **openapi:** document mfa recovery codes endpoints
([2773ca5](2773ca5))
* **otp:** add link_token_hash column to one_time_tokens table
([#2800](#2800))
([4148d39](4148d39))
* **otp:** add one_time_tokens query helpers
([#2797](#2797))
([f8520b4](f8520b4))
* **otp:** handle test OTPs and Twilio Verify on the one_time_tokens
path ([#2798](#2798))
([2e9ce6c](2e9ce6c))
* **otp:** switch one_time_tokens table to source of truth
([#2788](#2788))
([2c2acf6](2c2acf6))
* **otp:** write `expires_at` when creating `one_time_tokens`
([#2766](#2766))
([d7d6afd](d7d6afd))
* **saml:** add dedicated_scope option for SAML providers
([#2893](#2893))
([bfbe078](bfbe078))


### Bug Fixes

* allow OAuth client tokens on GET /user, keep modifying actions blocked
([#2926](#2926))
([3e79d85](3e79d85))
* assert password is rejected after magic link/OTP
([#2896](#2896))
([9eb0924](9eb0924))
* **deps:** bump go to 1.27.3 to distrust compromised x509 intermediates
([a8d7070](a8d7070))
* **deps:** bump go to 1.27.4 to fix net/http server crash
([#2922](#2922))
([8872586](8872586))
* **deps:** bump google.golang.org/grpc to v1.83.1 for vulncheck
([#2818](#2818))
([8861440](8861440))
* **deps:** bump otel to v1.45.0 for vulncheck
([946e3e3](946e3e3))
* **deps:** bump x/net to v0.60.0 for http2 vulns
([c3348e8](c3348e8))
* **linkedin:** avoid panic when the email response has no elements
([6311d50](6311d50))
* make password re-encryption on sign-in conditional
([#2906](#2906))
([84ff0c0](84ff0c0))
* **mfa:** ignore verify-disabled factors in recovery codes guard
([#2824](#2824))
([79ad7b2](79ad7b2))
* **mfa:** regenerate duplicate recovery codes
([#2793](#2793))
([8be2691](8be2691))
* **models:** exclude oauth client sessions from mfa step-up
invalidation ([#2801](#2801))
([#2802](#2802))
([ae468ca](ae468ca))
* only trigger after-user-created hook on account creation
([#2656](#2656))
([64cfdf2](64cfdf2))
* **openapi:** use ErrorSchema for identity unlink 401/403 responses
([60d4bb6](60d4bb6))
* **passkeys:** count friendly_name length by runes, not bytes
([ce9a8ee](ce9a8ee))
* restrict OAuth client access tokens to OAuth endpoints
([#2898](#2898))
([384d83a](384d83a))
* **sessions:** invalidate legacy sessions with null aal
([#2792](#2792))
([8977629](8977629))
* **tools:** bump staticcheck to read go 1.27.3 export data
([9e4f25b](9e4f25b))
* Update user password on each valid signup attempt
([#2868](#2868))
([004f767](004f767))
* Update user password on each valid signup attempt (fixed)
([#2918](#2918))
([2550341](2550341))
* **vulncheck:** ignore GO-2026-6909 (crewjam/saml, no fix available)
([#2909](#2909))
([bc90ec9](bc90ec9))


### Reverts

* Update user password on each valid signup attempt
([#2912](#2912))
([35307ce](35307ce))
* Update user password on each valid signup attempt (fixed)
[#2918](#2918)
([#2921](#2921))
([1357a5b](1357a5b))

---
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: supabase-releaser[bot] <223506987+supabase-releaser[bot]@users.noreply.github.com>
hf added a commit to supabase/supabase that referenced this pull request Nov 23, 2026
## What

Documents the SAML \`dedicated_scope\` option added in
[supabase/auth#2893](supabase/auth#2893) and
exposed in the CLI in
[supabase/cli#7665](supabase/cli#7665).

Some identity providers, notably Microsoft Entra, don't allow the same
entity ID in more than one application, so a project could connect only
one such app. A provider with a dedicated scope gets its own entity ID,
metadata URL, and ACS URL scoped to its provider ID.

## Changes

- `auth-sso-saml.mdx`: new "Use a dedicated scope for a connection"
section with the URL comparison, the `--dedicated-scope` flag, which
commands print the dedicated URLs, and a setup procedure for identity
providers (such as Okta) that need the URLs when the app is created. The
shared-URL table now links to it.
- `cli_v1_commands.yaml`: adds `--dedicated-scope` to `supabase sso
add`.

## Needs review

- The Entra-specific flow isn't verified. The procedure follows the Okta
workflow generically; it's unclear whether Entra rejects a second app
created with the shared entity ID.
- "Remove and add the connection again" to change scope is inferred,
because `sso update` doesn't accept the flag.
- No minimum CLI or Auth version is stated.
- The generated Management API reference isn't updated, since the
published spec doesn't document `dedicated_scope` yet.
- The self-hosted SAML page isn't checked.
- Not run: docs build, link and anchor checks, `test-the-docs`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Sonnet 5.5 <[email protected]>
sundeep8967 pushed a commit to sundeep8967/cli that referenced this pull request Nov 23, 2026
Adds a `--dedicated-scope` flag to `supabase sso add`, which sets the
SAML `dedicated_scope` option so the provider gets its own entity ID,
metadata URL and ACS URL.

- The field is create-only, so `sso update` does not accept it.
- `saml.dedicated_scope` is included in provider output (`sso show`,
`sso list`, and the json/yaml/toml formats).
- `sso show`, `add`, `remove` and `update` print the provider's own ACS
URL and entity ID in the text table when its scope is dedicated.
`update` takes the scope from the provider it fetches first, since its
response omits the field.
- `sso info` is unchanged.
- The Management API spec gets the field through
`openapi-overrides.json` until the published spec documents it.

Related: supabase/auth#2893, supabase/platform#42021

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants