Skip to content

fix(auth): disable self-service SSO provider registration - #8339

Merged
viktormarinho merged 3 commits into
mainfrom
fix/disable-sso-provider-registration
Nov 5, 2026
Merged

viktormarinho merged 3 commits into
mainfrom
fix/disable-sso-provider-registration

Conversation

@0xcucumbersalad

@0xcucumbersalad 0xcucumbersalad commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What is this contribution about?

Better Auth's sso() plugin mounts POST /api/auth/sso/register for 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, and sign-in/sso would 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:

  • sets providersLimit: 0 on the plugin, so registration returns 403 SSO provider registration is disabled. defaultSSO is unaffected.
  • adds migration 261-remove-user-registered-sso-providers, which deletes every ssoProvider row (all of them came from that endpoint), the account links created through them, and the sessions of users holding those links.

How did you verify your code works?

  • After merging main: bun run verify (13127 tests) and bun run check pass.
  • Migration 261 against a local Postgres seeded with a provider, an account linked through it and a session for that user, plus an unrelated user: it removes the provider, the linked account and that user's session, and leaves the unrelated user's account and session. It also returns cleanly when the ssoProvider table doesn't exist (Better Auth's migration can be skipped for a custom database).
  • Production currently holds 3 ssoProvider rows. All were registered by test accounts during a security report, with 1 linked test account and 2 sessions. No customer data is affected.
  • Earlier: bun run verify: format, lint and typecheck pass. 7 tests in apps/api/src/sandbox/content-storage.test.ts fail locally, and the same 7 fail on main without this change (local git environment). One timer test in ndjson-log-exporter.test.ts failed once under full-suite load and passes when run alone.
  • bun run --cwd=packages/e2e check passes.
  • Added packages/e2e/tests/sso-provider-registration.spec.ts: a signed-up user gets 403 from /sso/register, and sign-in/sso does not resolve a provider for that domain. Not run locally (no Postgres/NATS available); relying on CI.

How to Test

  1. Sign up a user.
  2. POST /api/auth/sso/register with any OIDC config.
  3. Expect 403. Operator SSO login and Settings → SSO keep working.

Migration Notes

Migration 261 only deletes data; it doesn't change the schema. Before deploying, check what it will remove:

SELECT "providerId", "userId", "organizationId", domain, issuer FROM "ssoProvider";

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

  • PR title is clear and descriptive
  • Changes are tested and working
  • Documentation is updated (if needed)
  • No breaking changes

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.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

@viktormarinho
viktormarinho merged commit c7e46da into main Nov 5, 2026
25 checks passed
@viktormarinho
viktormarinho deleted the fix/disable-sso-provider-registration branch November 5, 2026 23:07
decocms Bot pushed a commit that referenced this pull request Nov 5, 2026
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
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.

2 participants