📋 Description
src/routes/apiKeys.ts issues API keys, but keys appear to grant broad access rather than a narrow, declared set of scopes. There is no middleware that checks a request's required scope against the presenting key.
Why this matters: a leaked all-powerful key is a full compromise; a leaked read-only trust:read key is a contained incident. Least-privilege scoping turns key leakage from catastrophe into inconvenience.
🎯 Requirements & Context
Constraints: Express 4, Postgres, zod, existing RBAC in src/services/rbac. Coordinate with the auth middleware in src/middleware.
🛠️ Suggested Execution
git checkout -b feature/scoped-api-keys
- Migration + service changes +
requireScope middleware + route wiring + audit logging.
- supertest tests: key with scope passes, without scope gets 403, scope escalation rejected.
- TSDoc +
docs/api-keys.md documenting the scope vocabulary.
npm run test -- apiKeys
npm run migrate:lint
npm run lint && npm run build
Edge cases: revoked key, expired key, key with empty scope set, scope present but route not covered.
Example commit message
feat(auth): scoped API keys with requireScope least-privilege middleware
✅ Acceptance Criteria & Guidelines
| Requirement |
Target |
| Scope enforcement middleware + route wiring |
Required |
Migration passes migrate:lint / safety |
Required |
| Audit-logged key minting |
Required |
| Coverage of new code |
≥ 95% |
docs/api-keys.md |
Required |
| Timeframe |
96 hours |
💬 Community & Support
Security design questions → Credence Discord: https://discord.gg/nmnPBkBge. Comment here when you start. 🚀
📋 Description
src/routes/apiKeys.ts issues API keys, but keys appear to grant broad access rather than a narrow, declared set of scopes. There is no middleware that checks a request's required scope against the presenting key.
🎯 Requirements & Context
bond:read,bond:write,attestation:write,trust:read,payouts:write) as a typed enum.node-pg-migrate); default new keys to least privilege.requireScope(scope)Express middleware and apply it to the relevant routes.Constraints: Express 4, Postgres, zod, existing RBAC in src/services/rbac. Coordinate with the auth middleware in src/middleware.
🛠️ Suggested Execution
requireScopemiddleware + route wiring + audit logging.docs/api-keys.mddocumenting the scope vocabulary.Edge cases: revoked key, expired key, key with empty scope set, scope present but route not covered.
Example commit message
✅ Acceptance Criteria & Guidelines
migrate:lint/ safetydocs/api-keys.md💬 Community & Support
Security design questions → Credence Discord: https://discord.gg/nmnPBkBge. Comment here when you start. 🚀