Repository navigation
Let agents create and revoke their own API keys - #64
Conversation
One allowance for every caller: a subject is an API key or an anonymous visitor (a keyed hash of their IP, never the IP). New scans count against a daily limit that resets at UTC midnight; reused scans and reads don't. Keys are sp_ plus 32 random bytes, stored only as a SHA-256 with their first characters kept to tell them apart, at most 3 new keys a day per IP. Usage older than 30 days is dropped when keys are made. AccessStore sits beside Store: in memory for tests, Postgres in store-postgres with migration 0003 (row level security on, no policies). The web endpoints come next. Refs #36 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
POST /api/keys returns a new key once, with its daily limit and how to use and revoke it; a fourth key from one IP in a UTC day gets 429 with Retry-After. DELETE /api/keys/current revokes the key it's sent with. Requests made with a key are logged against it, never with the key itself. IPs are hashed with STACKPROBE_IP_HASH_SECRET, required in production. Closes #36 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Drippa Sign-Off: Self-serve API key creation and revocation for agents✅ Delivers ticket #36 — 5 of 5 outcomes What was promised
Not in this change: Spending the daily scan allowance from the scan API is left to #37. Proof Steps based on ticket #36, the pull request description and the code change. DetailsAgents can now get an API key by calling the key creation address, with no sign-up. The key is returned once, with a 10 new scans a day limit. They can revoke it by sending the key back. One address can create at most 3 keys a day; a fourth gets a clear limit message with the reset time. Caller addresses are only kept as a keyed hash, and responses are never cached. Test coverage: ✅ Well covered — Tests cover creating a key, the 3-a-day refusal with retry time, revoking, revoked and bad keys refused, usage recorded without the key, and reading the caller address. 🔍 Checked:
Updated by Drippa • 2026-10-12 18:28 UTC Comment |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Closes #41 Covers both "Done when" lines of #41: the limits and the bot check are tested (the bot check is behind a `BotCheck` interface, faked in tests), and reading reports is never limited. ## What changes - **`requestScan` allowance hook (core):** `allowance.check()` runs just before a new scan is created and can refuse it; `allowance.spend()` runs once the scan exists. Returning a running or fresh scan touches neither. - **`lib/start-scan.ts`:** the website's scan logic, with the server action now a thin wrapper. 1. **Bot check** first. A bot gets "We couldn't confirm this is a browser. Reload the page and try again." and nothing is created. 2. **Visitor allowance:** 3 new scans a day per visitor (`visitor:<hmac of IP>`, using `STACKPROBE_IP_HASH_SECRET` from #64). 3. **At the limit:** "You've started 3 new scans today, the daily limit without a key. Scans that already exist are still free to open. You can start more at midnight UTC, in N hours." - **"Scan again"** is now a small client component on the same action, so the limit message shows under the buttons instead of an error page. Form messages use `--ink-2`: a limit isn't a failure. - **Vercel BotID** (`botid`, MIT): - `withBotId` in `next.config.ts`; `initBotId` in `instrumentation-client.ts` protects POSTs, which is how scan forms submit. - `checkBotId()` runs in the action only on **Vercel production** (`VERCEL_ENV=production`). Previews skip it: they're behind Vercel's login already, and Drippa's review drives a headless browser there that BotID would refuse. - Self-hosted setups skip it too, since there's no BotID service. ## Checked - **Unit tests:** - 3 new scans, then the message, with nothing started. - Existing scans are free at the limit. - Scan again on a finished scan counts; while the scan is still running it doesn't. - Visitors are counted separately. - Bots are refused before anything is created. - Bad input spends nothing. - The message wording. - **Core:** the allowance is checked and spent only for new scans; a refusal creates nothing. - **Production build in a real browser (throwaway database):** - Three new scans from home open their reports; the fourth stays on home with the message. - Scan again at the limit shows the message under the buttons. - Opening an existing report still works. - Screenshots at 1280 px and 390 px. - `pnpm lint`, `pnpm typecheck`, `pnpm test` (385 passing), `pnpm build` pass. ## Notes - BotID's basic check is included on Vercel; nothing to turn on. It needs `NEXT_PUBLIC_VERCEL_ENV`, which Vercel exposes by default ("Automatically expose System Environment Variables"). - The bot check itself only runs on production, which is still behind Vercel's login, so it gets exercised for real once we open the site. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Closes #36
Stacked on #63 (keys and allowance in core and Postgres); merge that first and this retargets to
main.Covers #36's "Done when":
What changes
POST /api/keys→201 { key, prefix, limits: { scansPerDay: 10 }, note }. The note says to store the key now, send it asAuthorization: Bearer <key>, and revoke it withDELETE /api/keys/current. A fourth key from one IP in a UTC day →429 { error: "rate_limited", message, resetAt }withRetry-After.DELETE /api/keys/currentwith the key →200 { revoked: "<prefix>" }. Missing, malformed, unknown or revoked →401 { error: "invalid_key", message }withWWW-Authenticate: Bearer.key:<id>, never with the key.Cache-Control: no-storeandAccess-Control-Allow-Origin: *.x-forwarded-forentry (Vercel sets it), thenx-real-ip. It's hashed withSTACKPROBE_IP_HASH_SECRETand never stored as is. Production refuses to run without the secret; development uses a fixed stand-in. Added to.env.example.services.tsshares one Postgres connection between the scan store and the newgetAccess().Checked
Retry-After, revoke, then the revoked key failing, badAuthorizationheaders, usage logged without the key, andclientIp.POST /api/keys→ 201, the fourth → 429 with reset at the next UTC midnight;DELETE→ 200, again → 401. No key appears in the server log.pnpm lint,pnpm typecheck,pnpm testpass.Before deploying
STACKPROBE_IP_HASH_SECRETon Vercel (production and preview):openssl rand -base64 32.pnpm db:migrateagainst Supabase (migration 0003 from Add API keys and a daily new-scan allowance to core #63).🤖 Generated with Claude Code