Skip to content

fix: add structured audit logging for admin actions and auth outcomes - #1591

Open
boluxx123 wants to merge 1 commit into
LabsCrypt:mainfrom
boluxx123:security/issue-824-backend-no-structured-audit-logging-for
Open

boluxx123 wants to merge 1 commit into
LabsCrypt:mainfrom
boluxx123:security/issue-824-backend-no-structured-audit-logging-for

Conversation

@boluxx123

Copy link
Copy Markdown

Overview

This PR adds structured audit logging for destructive admin actions and authentication outcomes. Successful admin reset/replay operations now emit an audit entry capturing the actor's publicKey, action, params, and requestId, and verifyChallenge / requireAdmin log auth success and admin grant/deny with the publicKey — without leaking secrets or tokens.

Related Issue

Changes

🔐 Audit Logging Helper

  • [MODIFY] backend/src/logger.ts
    • Adds a small structured audit-log helper that emits consistent entries (actor publicKey, action, params, requestId) and strips/omits sensitive fields so no secrets or tokens land in the audit trail.

🛡️ Admin Route Audit Entries

  • [MODIFY] backend/src/routes/v1/admin.routes.ts
    • Successful reset/replay endpoints now emit a structured audit entry with the actor's publicKey, the action, the params passed, and the requestId — previously only the failure path was logged.

🔑 Auth & Admin Grant/Deny Logging

  • [MODIFY] backend/src/middleware/auth.ts
    • verifyChallenge logs auth success with the publicKey (error path already logged).
    • requireAdmin logs admin grant/deny with the publicKey.

🧪 Tests

  • [MODIFY] backend/tests/auth.test.ts
    • Covers auth success logging and admin grant/deny logging with publicKey.
  • [MODIFY] backend/tests/integration/reset-replay-race.test.ts
    • Covers audit entries for successful reset/replay under concurrent requests.

Verification Results

npm test -- backend/tests/auth.test.ts backend/tests/integration/reset-replay-race.test.ts
✅ tests passed

npm run lint
✅ no errors
Acceptance Criteria Status
Successful admin reset/replay emits a structured audit log entry (actor publicKey, action, params, requestId) ✅ Audit entry emitted on success in admin.routes.ts
verifyChallenge logs auth success, and requireAdmin logs grant/deny with the publicKey ✅ Logged in auth.ts
Audit entries are checked to be free of secrets/tokens ✅ Helper omits sensitive fields; covered by tests
tests + lint pass, CI green ✅ Tests and lint pass locally

Closes #824

@boluxx123
boluxx123 force-pushed the security/issue-824-backend-no-structured-audit-logging-for branch from 2239f4c to f4a8698 Compare October 1, 2026 11:43
@boluxx123
boluxx123 force-pushed the security/issue-824-backend-no-structured-audit-logging-for branch from f4a8698 to 1539caa Compare October 21, 2026 21:01

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Backend] No structured audit logging for destructive admin actions or auth outcomes

2 participants