Description
src/auth/middleware.ts's requireAdmin documents its callers as src/routes/diagnostics.ts, src/routes/events.ts, src/routes/backfill-events.ts, and src/routes/reprocess-events.ts, but successful admin authorizations are only counted (incAuthMetric(AUTH_METRICS.ADMIN_AUTHORIZED)), not recorded as a durable, queryable audit trail of who performed which privileged action and when. Add a dedicated audit log capturing admin identity, route, method, and outcome for every requireAdmin-gated request.
Requirements and context
- Add an
admin_audit_log table (address, method, path, status_code, request_id, created_at) to src/db/schema.ts
- Write an audit row from within
requireAdmin in src/auth/middleware.ts on both grant and deny, without blocking the request on the write
- Ensure no request bodies, tokens, or PII beyond the already-public wallet address are persisted
- Must be secure, tested, and documented
- Should be efficient and easy to review
Suggested execution
Fork the repo and create a branch
git checkout -b feature/admin-action-audit-log
Implement changes
- Update/Write:
src/auth/middleware.ts
- Update/Write:
src/db/schema.ts
- Add/Update tests:
src/auth/middleware.test.ts
- Add documentation:
docs/auth/middleware.md
- Include clear code comments and TS types
- Validate security assumptions
Test and commit
- Run tests:
pnpm test
- Cover edge cases
- Include test output and security notes
Example commit message
feat: add audit logging for admin-authorized actions
Guidelines
- Minimum 95 percent test coverage
- Clear documentation
- Timeframe: 96 hours
Description
src/auth/middleware.ts'srequireAdmindocuments its callers assrc/routes/diagnostics.ts,src/routes/events.ts,src/routes/backfill-events.ts, andsrc/routes/reprocess-events.ts, but successful admin authorizations are only counted (incAuthMetric(AUTH_METRICS.ADMIN_AUTHORIZED)), not recorded as a durable, queryable audit trail of who performed which privileged action and when. Add a dedicated audit log capturing admin identity, route, method, and outcome for everyrequireAdmin-gated request.Requirements and context
admin_audit_logtable (address, method, path, status_code, request_id, created_at) tosrc/db/schema.tsrequireAdmininsrc/auth/middleware.tson both grant and deny, without blocking the request on the writeSuggested execution
Fork the repo and create a branch
Implement changes
src/auth/middleware.tssrc/db/schema.tssrc/auth/middleware.test.tsdocs/auth/middleware.mdTest and commit
pnpm testExample commit message
Guidelines