Repository navigation
Conversation
The seed-admin endpoint had no auth and no environment guard (only a rate limit), despite its 'development/testing only' comment. On any deployment an anonymous request created admin@sonicjs.com / sonicjs! with role admin, and for an existing admin it overwrote the credential password — an unauthenticated admin takeover requiring zero misconfiguration. Gate it fail-closed to explicit non-production ENVIRONMENT values (development/test/e2e/preview/local), matching the test-cleanup routes. An unset or 'production' ENVIRONMENT is denied, so a default `wrangler deploy` cannot expose it. Production admin provisioning goes through the bootstrap seed path. The E2E preview runs with ENVIRONMENT=development, so seeding still works there; the denied path is covered by a unit test.
The ENVIRONMENT allowlist alone does not close the endpoint for create-sonicjs apps: the starter's wrangler.toml sets ENVIRONMENT = "development" in its top-level [vars], and its `npm run deploy` is a plain `wrangler deploy`, so a default deploy ships with ENVIRONMENT=development and the anonymous fixed-credential admin reset stays open. The route now also requires ENABLE_SEED_ADMIN = "true", set only in this repo's my-sonicjs-app/wrangler.toml (E2E preview and local dev). Nothing in the starter calls the route; it seeds through its own script. Also: correct the comment that pointed production admins at a "bootstrap seed path" (there is none on Workers; the first registered account becomes admin), and renumber the E2E spec 108 -> 114 (108 is taken on main).
Review follow-up on the seed-admin gate. - In an allowed (non-production) ENVIRONMENT without the opt-in, the 403 now says to set ENABLE_SEED_ADMIN = "true", so a developer isn't left guessing. Production keeps the generic message and never mentions the flag. - docs/authentication.md, ROUTE-MIGRATION.md, the authentication docs page and the postman README now say the endpoint needs the flag and a non-production ENVIRONMENT. The docs page's rate limit for it said 2 per minute; the code allows 10.
'Non-production' was looser than the code: only development, test, e2e, preview and local are allowed, so e.g. staging is refused.
This was referenced Oct 13, 2026
mmcintosh
marked this pull request as ready for review
October 13, 2026 20:12
11 tasks done
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
POST /auth/seed-adminis mounted on every deployment with no authentication and no environment guard: only a rate limit, and it is CSRF-exempt. On any live site, an anonymous request creates or resetsadmin@sonicjs.com/sonicjs!with the admin role and admin RBAC: if that account exists, its password is reset. It also creates or resets an editor,e@e.com. That is an unauthenticated admin takeover that needs no misconfiguration at all.Merge after #1104 (register form) and #1019 in this batch. This endpoint is one way into a broken fresh install, and those two PRs fix the normal way in, so closing it last avoids leaving people with no way in.
No public issue (security fix).
Changes
routes/auth.ts: the route needs both of these, or it returns 403:ENABLE_SEED_ADMIN = "true", an explicit opt-in;ENVIRONMENTset to one ofdevelopment,test,e2e,previeworlocal. Unset orproductionis refused.ENVIRONMENT = "development"in its top-level[vars], and itsnpm run deployis a plainwrangler deploy. So a default deploy ships as "development".my-sonicjs-app/wrangler.toml: setsENABLE_SEED_ADMIN = "true"in the test app's top-level[vars], used by the CI preview and local dev, so E2E seeding still works. Never deploy that app for real with it set.seed-self-host.ts.ENABLE_SEED_ADMIN. Any other environment, including unset, gets a generic message.wrangler dev, must addENABLE_SEED_ADMIN = "true"to their local vars to keep using seed-admin.docs/authentication.md,packages/core/ROUTE-MIGRATION.md,www/src/app/authentication/page.mdxandtests/postman/README.mdnow describe the gate. The authentication page's seed-admin rate limit is corrected from 2 to 10 per minute.main.Testing
seed-admin-gate.test.ts(13 tests):Production;falseor empty in development;Unit Tests
E2E Tests
114-seed-admin-env-gate.spec.ts(@smoke @auth). It guards that seeding and admin login still work in the preview. The refused cases are covered by the unit test, because the preview can't be switched to production.Screenshots/Videos
N/A. No UI changes.
Checklist