fix(api): auth-gate /api/setup and /api/seed operator endpoints - #174
Open
dirtybits wants to merge 1 commit into
Open
fix(api): auth-gate /api/setup and /api/seed operator endpoints#174dirtybits wants to merge 1 commit into
dirtybits wants to merge 1 commit into
Conversation
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 /api/setupandPOST /api/seedwere the only operator state-mutatingAPI endpoints with no authentication at all — no
middleware.tsexists andno route-level auth check, so they were internet-reachable in production.
Concrete risk on a fresh production deploy (empty Postgres):
POST /api/seed(no auth,200on success): an anonymous caller couldinject the demo seed skill + version rows into the live
skills/skill_versionstables (the route only skips whenSELECT COUNT(*) FROM skillsis non-zero).POST /api/setup: re-runsbootstrapDatabase()DDL against the live DB.Both are also redundant for schema work:
ensureUsdcPurchaseSchema()andensureAgentIdentitySchema()already run on the request path, and VercelPostgres persists between deployments.
Fix: gate both routes with the exact auth pattern already used by the
equally-operator-facing
POST /api/github/skills/discover(and the cronroutes): Bearer
CRON_SECRET, constant-time compare, and — matching thestronger discover variant — fail closed in both production and preview
(preview deployments are internet-reachable). No secret + local development =
open, so the local dev flow is unchanged.
Test Plan
npm run format:check— clean (prettier).npm run lint:web— clean (eslint).npm run typecheck— clean (next typegen && tsc --noEmit).npm run test:web— 130 files / 965 tests pass, including:web/__tests__/api/setup.test.ts(7 tests): local-open, 500passthrough, and 401 fail-closed in production/preview with secret unset,
missing token, wrong token; 200 with valid token.
web/__tests__/api/seed-route.test.ts(7 tests): same auth matrix +seed-into-empty-DB and skip-when-populated behavior.
npm exec --workspace @agentvouch/web -- next build --webpack— buildssuccessfully (explicit webpack per AGENTS.md bundler-parity gate).
Operational note (deploy)
If anything in the deploy/provisioning flow calls these endpoints in
production or preview (no in-repo callers found — CI, vercel.json, scripts,
and docs were all checked), set
CRON_SECRETon the Vercel project; the sameenv var is already used by the cron + discover endpoints, so no new secret is
introduced. Until it is set, these two endpoints return 401 in deployed
environments while remaining open locally.
Signing caveat
Committed unsigned: this headless runner has no GPG secret key for the
repo's signing identity (
gpg: skipped "andy <dirtybitsofficial@gmail.com>": No secret key) and no 1Password agent. To re-sign before merging: