Skip to content

fix(auth): turn signup approval on by default - #2919

Merged
simple-agent-manager[bot] merged 4 commits into
mainfrom
sam/signup-approval-default-on
Nov 20, 2026
Merged

simple-agent-manager[bot] merged 4 commits into
mainfrom
sam/signup-approval-default-on

Conversation

@simple-agent-manager

@simple-agent-manager simple-agent-manager Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Signup approval is now on by default. envRequiresApproval() (apps/api/src/services/signup-approval.ts) returned env.REQUIRE_APPROVAL === 'true'. That meant an installation that never set the variable gave an active account to anyone who could sign in. It now returns true unless the value is false (trimmed, case-insensitive). Unset values and typos keep approval on, so it fails closed.
  • Unchanged: the Admin → Users runtime switch still overrides the variable (getSignupApprovalConfig). The first real account is still promoted to an active superadmin by establishFirstSuperadmin (role='superadmin', status='active'), so a fresh install does not lock its owner out. The installer BOOTSTRAP_OWNER_EMAIL path is untouched.
  • Who this changes:
    • Canonical production and staging already set REQUIRE_APPROVAL=true as GitHub Environment variables (checked with gh variable list --env production|staging), so their behaviour does not change.
    • Self-hosted installations that never set the variable or used the switch will create new accounts as pending after updating. Existing accounts are unchanged. self-hosting.mdx gets an upgrade note.
  • Docs: configuration.md (default column and description), self-hosting.mdx (the default, how to opt out, the upgrade note), installer.mdx and .env.example now say approval is on by default. Root CLAUDE.md, the blog authoring guide, and yesterday's WIF journal post (docs: frame SAM as self-hosted, not SaaS (WIF journal post + agent instructions) #2909) no longer say approval is off by default.
  • Raphaël asked for this to go straight to production (2026-11-20): "Let's switch it immediately. No need to test in staging."

Validation

  • pnpm --filter @simple-agent-manager/api typecheck: passed
  • eslint on the changed API files: passed
  • API unit and integration tests (tests/unit/services/, tests/unit/routes/, tests/unit/auth.test.ts, tests/integration/agent-sign-in.test.ts): 10,623 passed, 3 skipped, after the fixes below
  • Workers tests signup-approval-gate, superadmin-self-heal, owner-session-snapshot-export: 106/106 passed. CI runs the full Workers suite.
  • CI on 7529cd3: every check green, including all 7 Durable Object Workers shards with approval on by default. An earlier Test api (1/3) failure was workspace-proxy-ownership.test.ts: its mocked session user had no status, so the new default held it for approval. Real user rows always carry a status, so the mock now has status: 'active' (7529cd3). The full local API unit suite then passed: 16,110 tests.
  • Discrimination check: with the old one-line default restored, 6 new tests fail. They are the unset default, '', yes, the typo flase, the real BetterAuth user.create.before hook creating a pending account with the variable unset, and the MCP token gate rejecting a pending owner with the variable unset. ' FALSE ' is the opt-out control and passes either way.
  • Tests updated, not weakened: these tests modelled an opted-out installation by leaving the variable unset. They now say so explicitly:
    • mcp-token-lifecycle.test.ts: the base env sets REQUIRE_APPROVAL: 'false'.
    • platform-config-cache.test.ts: the test starts from an explicit runtime "off" row before checking that turning approval on is not cached.
    • One superadmin-self-heal test name no longer says "open registration".
  • pnpm quality:agent-context-budget --check: passes. Prettier is clean on every changed file that was clean on main.
  • N/A: sweep/cron/alarm candidate selection.

Staging Verification (REQUIRED for all code changes — merge-blocking)

Waived by Raphaël for this PR ("No need to test in staging… Get it into prod now", 2026-11-20). Also, the canonical staging environment already runs with REQUIRE_APPROVAL=true, so a staging deploy would not exercise the changed default. The changed path, a variable that is unset, is covered by the tests above, which go through the real BetterAuth hook and MCP gate.

  • Staging deployment green: waived (see above)
  • Infrastructure verification: N/A: no infra changes
  • Mobile and desktop verification: N/A: no UI change

UI Compliance Checklist (Required for UI changes)

N/A: no app UI changed.

End-to-End Verification (Required for multi-component changes)

N/A: one function's default changed, in a single component. Every reader goes through envRequiresApproval:

  • getSignupApprovalConfig → isSignupApprovalRequired (BetterAuth user.create.before in auth.ts, assertSessionUserApproved)
  • signupApprovalRequiredFromStoredValue (MCP token lifecycle)

Both paths are tested with the variable unset.

Post-Mortem (Required for bug fix PRs)

What broke

A self-hosted installation with no REQUIRE_APPROVAL set used open registration. Anyone who could reach its sign-in got an active account.

Root cause

The default was "off unless true". The maintainers' own environments set the variable explicitly, so the open default was never seen in daily use.

Class of bug

Fail-open default on an access gate, hidden by explicit configuration in the environments the maintainers use.

Process fix

Tests now pin the unset case through the real entry points, so a regression to fail-open breaks CI.

Specialist Review Evidence

  • All local reviewers completed and findings addressed before merge
  • If any reviewer did NOT complete: needs-human-review label added and merge deferred to human (N/A so far)
Reviewer Status Outcome
security-auditor (local subagent) ADDRESSED 0 CRITICAL/HIGH. It confirmed every reader and every account-creation path gets the new default. Token-login, device flow and workload-identity login only open sessions for existing users and re-check approval. No code outside BetterAuth inserts users, apart from deliberate operator scripts. The first user is still elected active superadmin, and no system account is created at runtime. 2 MEDIUM, fixed in df8298c: the unit tests mock D1, and no test showed a pending first user under the default being promoted. A new Workers test on Miniflare D1 chains the real user.create.before hook (variable unset) into the real session.create.before election and asserts active superadmin. LOW, not acted on: routes using requireAuth without requireApproved are reachable by pending accounts. That is the documented pending-account surface (sign in, see the waiting state, link a GitHub App installation), and canonical production has run with approval on since February. Operator scripts that insert active users bypass the hook, which is intended. Two simultaneous first sign-ups leave no admin, which is pre-existing and not made worse.

CodeRabbit Review Evidence

  • CodeRabbit requested when the PR was opened ready for review (coderabbit-review label at 00:20 UTC; request workflow passed)
  • Waited for it: at 00:24 UTC CodeRabbit replied Review skipped, which ends the wait (rule 25)

CodeRabbit Notes

No review: Review skipped. Nothing is unresolved.

Other review bots

Codex (P1, fixed in 832c77e, resolved): the docs claimed the new default without citing code. installer.mdx, the configuration.md row and .env.example now cite envRequiresApproval. Codex's re-review of 832c77e reports no unresolved findings.

Agent Preflight (Required)

  • Preflight completed before code changes

Classification

  • external-api-change
  • cross-component-change
  • business-logic-change
  • public-surface-change
  • docs-sync-change
  • security-sensitive-change
  • ui-change
  • infra-change

External References

None. The change uses no external API.

Codebase Impact Analysis

Readers of the default:

  • envRequiresApproval (signup-approval.ts), used by getSignupApprovalConfig, isSignupApprovalRequired and signupApprovalRequiredFromStoredValue
  • auth.ts user.create.before
  • mcp-token-lifecycle.ts
  • the session gates

Not affected: first-user election (first-superadmin.ts, which sets active), the installer owner path (bootstrapUserDecision), and the admin runtime switch (routes/admin.ts, setSignupApprovalConfig).

Deploy wiring: REQUIRE_APPROVAL is forwarded from GitHub Environment variables in deploy-reusable.yml and sync-wrangler-config.ts, and that is unchanged. Production and staging already set it to true.

Documentation & Specs

configuration.md, self-hosting.mdx (default, opt-out and upgrade note), installer.mdx, .env.example, root CLAUDE.md, apps/www/src/content/CLAUDE.md, and the WIF journal post. No specs touched.

Constitution & Risk Check

Principle XI: the value stays configurable (environment variable plus runtime switch); only the default changes, to fail closed. Risk: self-hosters who rely on open signup must opt out after updating. This is documented in the upgrade note.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@simple-agent-manager simple-agent-manager Bot added the coderabbit-review Trigger CodeRabbit review for opt-in PRs label Nov 20, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T01:16:22.681063Z 7529cd3 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@raphaeltm

Copy link
Copy Markdown
Owner

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Action not completed

Head commit changed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8b20c52541

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

simple-agent-manager Bot pushed a commit that referenced this pull request Nov 20, 2026
Addresses Codex review on #2919.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
raphaeltm and others added 4 commits November 20, 2026 01:14
Signup approval was off unless REQUIRE_APPROVAL was exactly "true", so a
self-hosted installation reachable from the internet handed an active
account to anyone who could sign in. It is now on unless the deployment
sets REQUIRE_APPROVAL=false; any other value, including unset or a typo,
keeps it on. The Admin -> Users runtime switch still overrides it, and the
first real account is still promoted to an active superadmin.

The canonical production and staging environments already set
REQUIRE_APPROVAL=true, so they do not change. Self-hosted installations
that never set the variable or used the switch will create new accounts
as pending after updating; existing accounts are unchanged. The
self-hosting guide gets an upgrade note.

Tests drive the real BetterAuth user-create hook and the MCP token gate
with the variable unset; they fail against the old default. Tests that
modelled an opted-out installation now set REQUIRE_APPROVAL=false or a
runtime "off" row explicitly. Docs, .env.example, CLAUDE.md, the blog
authoring guide and yesterday's WIF journal post stop saying approval is
off by default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Chains the real user.create.before hook (REQUIRE_APPROVAL unset, Miniflare
D1) into the real session.create.before election and asserts the pending
first account becomes an active superadmin. Addresses security review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Addresses Codex review on #2919.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The mocked BetterAuth session user had no status. With signup approval on
by default, a statusless non-admin is held for approval, so the proxy
returned 403. Real user rows always carry status; the mock now says active.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@simple-agent-manager
simple-agent-manager Bot force-pushed the sam/signup-approval-default-on branch from 832c77e to 7529cd3 Compare November 20, 2026 01:14
@sonarqubecloud

Copy link
Copy Markdown

@simple-agent-manager
simple-agent-manager Bot merged commit 7dd027f into main Nov 20, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coderabbit-review Trigger CodeRabbit review for opt-in PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant