fix(auth): gate /auth/seed-admin to non-production environments - #1063
Draft
mmcintosh wants to merge 1 commit into
Draft
fix(auth): gate /auth/seed-admin to non-production environments#1063mmcintosh wants to merge 1 commit into
mmcintosh wants to merge 1 commit into
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.
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.
Summary
POST /auth/seed-adminwas mounted on every deployment with no authentication and no environment guard — only a rate limit — despite its "development/testing only" comment. On any live instance an anonymous request would createadmin@sonicjs.comwith a fixed password and roleadmin, and for an already-existing admin it would overwrite that account's credential password. That is an unauthenticated admin-takeover path requiring zero misconfiguration.Fix
Gate the endpoint fail-closed to explicit non-production
ENVIRONMENTvalues (development/test/e2e/preview/local), matching the existingtest-cleanuproutes. An unset orproductionENVIRONMENTis denied with403, so a defaultwrangler deploycannot expose it. Production admin provisioning continues to go through the bootstrap seed path, not this route.Compatibility
The CI preview and local dev both run with
ENVIRONMENT=development(an allowed value), so the seeding path the E2E suite and first-boot login depend on is unchanged.Tests
packages/core/src/__tests__/routes/seed-admin-gate.test.ts— 9 cases:production/ unset / unrecognized / mixed-case denied (403);development/test/e2e/preview/localallowed.tests/e2e/108-seed-admin-env-gate.spec.ts— regression guard that seeding + login still succeed in the development preview.