Skip to content

fix(den): block email OTP sign-in under required SSO and dedupe SSO start request - #5138

Open
alexgvozden wants to merge 3 commits into
different-ai:devfrom
alexgvozden:fix/sso-otp-guard-and-duplicate-start
Open

alexgvozden wants to merge 3 commits into
different-ai:devfrom
alexgvozden:fix/sso-otp-guard-and-duplicate-start

Conversation

@alexgvozden

Copy link
Copy Markdown

Summary

  • den-api: the single-org SSO-only guard now rejects POST /sign-in/email-otp in addition to email/password sign-in and sign-up.
  • den-web: the org SSO sign-in page sends one sign-in/sso request per attempt, even when React runs the effect twice.

Why

  • Email OTP sign-in issues a session and creates unknown users just like email/password. On a deployment where SSO is configured and required, it was a way to sign in without going through the identity provider.
  • React StrictMode runs effects twice in dev. The second sign-in/sso call overwrote the OAuth state cookie, so the IdP callback failed with state_mismatch.

Issue

  • N/A

Scope

  • ee/apps/den-api/src/routes/auth/index.ts: new isBetterAuthEmailOtpSignInRequest matcher, used in getSingleOrgAuthGuardResponse.
  • ee/apps/den-web/app/sso/[orgSlug]/page.tsx: in-flight requests are kept in a ref keyed by org slug, callback URLs, login hint and attempt number. Retry still sends a new request because the attempt number changes.
  • ee/apps/den-api/test/single-org-route-guards.test.ts: test for the new matcher.

Out of scope

  • Other OTP routes (/email-otp/send-verification-otp and similar). Only the route that issues a session is blocked.
  • Multi-org deployments. The guard only applies in single-org mode with SSO configured.

Testing

Ran

  • bun test --conditions development test/single-org-route-guards.test.ts (in ee/apps/den-api)
  • pnpm exec tsc --noEmit -p . (in ee/apps/den-web)

Result

  • pass/fail: 10 pass, 0 fail. den-web typecheck clean.
  • if fail, exact files/errors: bun intermittently reports 1 "unhandled error between tests" (Unknown database 'openwork_test' from a background oauthResource query). It appeared in some runs and not others, with or without this change, and needs a local test database that my machine does not have.

CI status

  • pass: pending
  • code-related failures: pending
  • external/env/auth blockers: pending

Manual verification

  1. Not run as part of this PR. The end-to-end guard response (sso_required for POST /api/auth/sign-in/email-otp) is covered only by the matcher unit test.
  2. The state_mismatch fix was not re-verified in a browser after these commits.

Evidence

  • N/A

Risk

  • Low. The den-api change only adds one more route to an existing guard branch that runs only when single-org SSO is configured. The den-web change only deduplicates an identical request.

Rollback

  • Revert the three commits. No migrations or config changes.

🤖 Generated with Claude Code

alexgvozden and others added 3 commits September 18, 2026 16:12
Email OTP sign-in issues a session and creates unknown users just like
email/password, so the single-org SSO guard now rejects it too.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
React StrictMode runs the sign-in effect twice in dev. The second
sign-in/sso call overwrote the OAuth state cookie, so the callback
failed with state_mismatch. Both runs now await the same request.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@alexgvozden
alexgvozden requested a review from a team September 18, 2026 12:27
@vercel

vercel Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

@alexgvozden is attempting to deploy a commit to the Different AI Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
vercel Bot temporarily deployed to Preview – openwork-landing September 18, 2026 12:27 Inactive
@vercel
vercel Bot temporarily deployed to Preview – openwork-app September 18, 2026 12:27 Inactive
@vercel
vercel Bot temporarily deployed to Preview – openwork-diagnostics September 18, 2026 12:27 Inactive
@vercel

vercel Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

3 Skipped Deployments
Project Deployment Actions Updated
openwork-app Skipped Skipped Sep 18, 2026 12:27pm UTC
openwork-diagnostics Skipped Skipped Sep 18, 2026 12:27pm UTC
openwork-landing Skipped Skipped Sep 18, 2026 12:27pm UTC

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.

1 participant