Skip to content

fix(auth): gate /auth/seed-admin to non-production environments - #1063

Draft
mmcintosh wants to merge 1 commit into
mainfrom
fix/seed-admin-env-gate
Draft

fix(auth): gate /auth/seed-admin to non-production environments#1063
mmcintosh wants to merge 1 commit into
mainfrom
fix/seed-admin-env-gate

Conversation

@mmcintosh

Copy link
Copy Markdown
Collaborator

Summary

POST /auth/seed-admin was 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 create admin@sonicjs.com with a fixed password and role admin, 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 ENVIRONMENT values (development / test / e2e / preview / local), matching the existing test-cleanup routes. An unset or production ENVIRONMENT is denied with 403, so a default wrangler deploy cannot 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 / local allowed.
  • tests/e2e/108-seed-admin-env-gate.spec.ts — regression guard that seeding + login still succeed in the development preview.
  • Full core suite green (1746 passed); type-check clean.

Marked draft pending maintainer review of the disclosure/coordination approach.

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