Skip to content

feat(backend): audit logging for sensitive operations (#793) - #985

Merged
Smartdevs17 merged 1 commit into
Smartdevs17:mainfrom
sandrawillow001-afk:feat/793-audit-logging-sensitive-operations
Sep 28, 2026
Merged

Smartdevs17 merged 1 commit into
Smartdevs17:mainfrom
sandrawillow001-afk:feat/793-audit-logging-sensitive-operations

Conversation

@sandrawillow001-afk

Copy link
Copy Markdown
Contributor

Summary

Records authentication, payment, admin, identity, and compliance requests in the tamper-evident audit log, capturing timestamp, user, action, IP, and outcome for every sensitive operation.

Closes #793

Changes

  • New sensitiveAudit middleware (backend/src/middleware/sensitiveAudit.ts):
    • classifies sensitive paths into auth, payments, admin, identity, compliance
    • logs on response finish; aborted connections are recorded as failure
    • configurable excludePaths, actionMapper, and userIdResolver
  • AuditService gains a first-class outcome field, derived from the response status when omitted, included in the entry hash and CSV export.
  • Middleware mounted for all API routes; POST /api/v1/audit/log now accepts outcome.
  • Fixed audit resource derivation (payments instead of v1) and removed a stale compiled auditService.js that shadowed the TypeScript source during tests.
  • Docs: docs/security/audit-logging.md.

Testing

  • cd backend && npx vitest run src/middleware/__tests__/audit.test.ts src/middleware/__tests__/sensitiveAudit.test.ts src/services/__tests__/auditService.test.ts → 18 passed (16 new)
  • npx eslint on changed files → 0 errors

Record authentication, payment, admin, identity, and compliance requests in
the tamper-evident audit log so every sensitive action captures who did what,
from where, and with what result.

- Add sensitiveAudit middleware that classifies sensitive paths and logs
  timestamp, user, action, resource, IP, user agent, and outcome on response
  finish, treating aborted connections as failures
- Add a first-class outcome field to AuditService entries (derived from the
  response status when not supplied) and include it in hashing and CSV export
- Mount the middleware for all API routes and allow outcome in POST /audit/log
- Fix audit resource derivation (payments instead of v1) and remove stale
  compiled auditService.js that shadowed the TypeScript source in tests
- Document the behaviour and add unit tests

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
@vercel

vercel Bot commented Sep 28, 2026

Copy link
Copy Markdown

@sandrawillow001-afk is attempting to deploy a commit to the smartdevs17's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Sep 28, 2026

Copy link
Copy Markdown

@sandrawillow001-afk Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Smartdevs17
Smartdevs17 merged commit 23cc8e1 into Smartdevs17:main Sep 28, 2026
2 of 3 checks passed
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.

Add comprehensive audit logging for all sensitive operations

2 participants