Skip to content

Block sign-ups from configured email domains - #532

Open
arseniycodes wants to merge 1 commit into
mainfrom
signup-blocked-email-domains
Open

arseniycodes wants to merge 1 commit into
mainfrom
signup-blocked-email-domains

Conversation

@arseniycodes

@arseniycodes arseniycodes commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • New SIGNUP_BLOCKED_EMAIL_DOMAINS env var on the api: a comma-separated list of email domains that may not create accounts. Subdomains of a listed domain are blocked too; matching is case-insensitive and uses the domain after the last @.
  • Enforced in Better Auth's databaseHooks.user.create.before, so it applies to email/password, Google/GitHub, and admin-created users. A blocked attempt returns 403 {"message":"Sign-ups from this email domain are not allowed."} and writes no user row.
  • Unset (the default) blocks nothing, so local dev and self-hosted deployments are unaffected.

Useful for shutting off a domain that's sending spam sign-ups without a code change.

Testing

  • signup-email-domains.test.ts: parsing, case-insensitivity, subdomains, lookalike domains (notspam.example, spam.example.org), and quoted local parts.
  • Checked end to end with Better Auth's memory adapter: POST /api/auth/sign-up/email with a blocked domain → 403 and no user stored; an allowed domain → 200.
  • pnpm --filter @superlog/api typecheck passes.

🤖 Generated with Claude Code


Summary by cubic

Adds a SIGNUP_BLOCKED_EMAIL_DOMAINS env var that blocks account creation from listed email domains, so a domain sending spam sign-ups can be shut off without redeploying.

New Features

  • Accepts a comma-separated domain list; matching is case-insensitive, covers subdomains, and compares the part after the last @.
  • Enforced in Better Auth's user creation hook for email/password, social, and admin-created users; blocked attempts return 403 and write no user row.
  • Unset by default, so local dev and self-hosted deployments block nothing.

Written for commit a57e6ba. Summary will update on new commits.

View guided diff Turn on auto-fix

Adds SIGNUP_BLOCKED_EMAIL_DOMAINS, a comma-separated list of email
domains (and their subdomains) that may not create accounts. Enforced in
Better Auth's user.create.before hook, so it covers email/password,
social, and admin-created users alike. Blocked attempts get a 403 and no
user row is written. Unset = nothing blocked.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Copy link
Copy Markdown
Contributor Author

@codex review

@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.

No issues found across 3 files

View guided diff | Turn on auto-fix | Re-trigger cubic

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: a57e6ba041

ℹ️ 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".

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T17:03:14.977209Z a57e6ba Manual request
ℹ️ 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.

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