Skip to content

Add structured audit logging for every requireAdmin-authorized action across diagnostics, backfill, and reprocess routes #657

Description

@Jagadeeshftw

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSGrantFox open-source programMaybe RewardedGrantFox: potentially rewarded contributionOfficial Campaign | FWC26GrantFox official campaign issuebackendBackend / API worksecuritySecurity hardening / audit

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions