Repository navigation
fix(auth): disable self-service SSO provider registration - #8339
Conversation
Better Auth's sso() plugin mounted /api/auth/sso/register for any signed-in user, with no org scope or domain verification. Nothing in Studio uses it: operator SSO comes from defaultSSO and org SSO has its own routes. Set providersLimit to 0 and remove providers already registered through it, along with the account links and sessions they created.
There was a problem hiding this comment.
3 issues found across 4 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/e2e/tests/sso-provider-registration.spec.ts">
<violation number="1" location="packages/e2e/tests/sso-provider-registration.spec.ts:16">
P2: This test uses the shared `example.test` domain, violating the suite’s unique-domain rule and allowing persisted or default SSO configuration to affect the assertion. Generate a per-run domain and reuse it in both the registration payload and lookup email.</violation>
<violation number="2" location="packages/e2e/tests/sso-provider-registration.spec.ts:33">
P2: `signIn.ok()` accepts any non-2xx response, so a 401, 422, or 500 would make this regression test pass. Assert the expected no-provider response status (and stable error code, if available) instead.</violation>
</file>
<file name="apps/api/migrations/261-remove-user-registered-sso-providers.ts">
<violation number="1" location="apps/api/migrations/261-remove-user-registered-sso-providers.ts:20">
P1: This provider-ID-only cleanup can delete unrelated operator or social accounts when a self-service provider reused an existing provider ID. Abort or handle provider-ID collisions before deleting account links, rather than treating every matching `account.providerId` as belonging to the registered provider.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
|
|
||
| await sql` | ||
| DELETE FROM "account" | ||
| WHERE "providerId" IN (SELECT "providerId" FROM "ssoProvider") |
There was a problem hiding this comment.
P1: This provider-ID-only cleanup can delete unrelated operator or social accounts when a self-service provider reused an existing provider ID. Abort or handle provider-ID collisions before deleting account links, rather than treating every matching account.providerId as belonging to the registered provider.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At apps/api/migrations/261-remove-user-registered-sso-providers.ts, line 20:
<comment>This provider-ID-only cleanup can delete unrelated operator or social accounts when a self-service provider reused an existing provider ID. Abort or handle provider-ID collisions before deleting account links, rather than treating every matching `account.providerId` as belonging to the registered provider.</comment>
<file context>
@@ -0,0 +1,26 @@
+
+ await sql`
+ DELETE FROM "account"
+ WHERE "providerId" IN (SELECT "providerId" FROM "ssoProvider")
+ `.execute(db);
+
</file context>
| const signIn = await ctx.post("/api/auth/sign-in/sso", { | ||
| data: { email: "[email protected]", callbackURL: "/" }, | ||
| }); | ||
| expect(signIn.ok()).toBe(false); |
There was a problem hiding this comment.
P2: signIn.ok() accepts any non-2xx response, so a 401, 422, or 500 would make this regression test pass. Assert the expected no-provider response status (and stable error code, if available) instead.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/e2e/tests/sso-provider-registration.spec.ts, line 33:
<comment>`signIn.ok()` accepts any non-2xx response, so a 401, 422, or 500 would make this regression test pass. Assert the expected no-provider response status (and stable error code, if available) instead.</comment>
<file context>
@@ -0,0 +1,36 @@
+ const signIn = await ctx.post("/api/auth/sign-in/sso", {
+ data: { email: "[email protected]", callbackURL: "/" },
+ });
+ expect(signIn.ok()).toBe(false);
+
+ await ctx.dispose();
</file context>
| data: { | ||
| providerId, | ||
| issuer, | ||
| domain: "example.test", |
There was a problem hiding this comment.
P2: This test uses the shared example.test domain, violating the suite’s unique-domain rule and allowing persisted or default SSO configuration to affect the assertion. Generate a per-run domain and reuse it in both the registration payload and lookup email.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/e2e/tests/sso-provider-registration.spec.ts, line 16:
<comment>This test uses the shared `example.test` domain, violating the suite’s unique-domain rule and allowing persisted or default SSO configuration to affect the assertion. Generate a per-run domain and reuse it in both the registration payload and lookup email.</comment>
<file context>
@@ -0,0 +1,36 @@
+ data: {
+ providerId,
+ issuer,
+ domain: "example.test",
+ oidcConfig: {
+ clientId: "client",
</file context>
PR: #8339 fix(auth): disable self-service SSO provider registration Bump type: patch - decocms (apps/api/package.json): 4.552.2 -> 4.552.3 - @decocms/e2e (packages/e2e/package.json): 1.130.5 -> 1.130.6 Deploy-Scope: server
What is this contribution about?
Better Auth's
sso()plugin mountsPOST /api/auth/sso/registerfor any signed-in user. With the plugin's defaults, a user could register up to 10 OIDC providers with no organization scope and no domain verification, andsign-in/ssowould then route logins to them.Studio doesn't use this endpoint. Operator SSO (Google/Microsoft) comes from
defaultSSO, and per-organization SSO in Settings → SSO uses its own owner-gated routes under/api/:org/sso/*and its own storage.This PR:
providersLimit: 0on the plugin, so registration returns403 SSO provider registration is disabled.defaultSSOis unaffected.261-remove-user-registered-sso-providers, which deletes everyssoProviderrow (all of them came from that endpoint), theaccountlinks created through them, and the sessions of users holding those links.How did you verify your code works?
main:bun run verify(13127 tests) andbun run checkpass.ssoProvidertable doesn't exist (Better Auth's migration can be skipped for a custom database).ssoProviderrows. All were registered by test accounts during a security report, with 1 linked test account and 2 sessions. No customer data is affected.bun run verify: format, lint and typecheck pass. 7 tests inapps/api/src/sandbox/content-storage.test.tsfail locally, and the same 7 fail onmainwithout this change (local git environment). One timer test inndjson-log-exporter.test.tsfailed once under full-suite load and passes when run alone.bun run --cwd=packages/e2e checkpasses.packages/e2e/tests/sso-provider-registration.spec.ts: a signed-up user gets 403 from/sso/register, andsign-in/ssodoes not resolve a provider for that domain. Not run locally (no Postgres/NATS available); relying on CI.How to Test
POST /api/auth/sso/registerwith any OIDC config.Migration Notes
Migration 261 only deletes data; it doesn't change the schema. Before deploying, check what it will remove:
Any user signed in through one of these providers is logged out, and that SSO link is removed.
down()is a no-op.Review Checklist