feat: Add structured audit records for auth operations - #701
Merged
MaryammAli merged 1 commit intoAug 27, 2026
Merged
Conversation
- Added AuditLogService with redaction for tokens/secrets - Correlated sessions and device trust events with audit logs - Intercepted auth operations (login, refresh, logout, reuse) for auditing - Updated modules to ensure proper dependency injection
|
@Opulencechuks 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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #589
Description
This PR addresses the critical need for comprehensive and structured audit logging within our authentication, logging, and audit services. Previously, authentication operations emitted standard application logs but lacked a structured, queryable audit trail.
This update introduces a robust, centralized auditing mechanism that rigorously tracks authentication flows, session lifecycles, token reuse attempts, and device trust modifications without leaking sensitive credentials into the logs.
Technical Implementation Details
1. Centralized Audit Service
AuditLogServiceand its related module from the localizedcourses/auditdomain and promoted it to a top-levelsrc/audit/AuditModule. This establishes it as the global standard for generating structured audit logs across the entire application.AuditModulein the rootAppModuleand imported it into theAuthModuleto make it accessible to the authentication lifecycle.2. Strict Context Sanitization
sanitize()mechanism inside theAuditLogService. Before anyrequestContextor metadata is committed to the logs, it aggressively filters and redacts keys containing sensitive substrings (e.g.,password,token,secret,authorization,cookie,refreshToken,accessToken).3. Structured Auth Event Hooking
Injected the
AuditLogServiceintoAuthSessionServiceand instrumented the following operations:createSession): Captures successful session creations, tracking the newly generatedsessionIdand any provideddeviceHash.refreshTokens):reuse_detectionfailure event if an attempt is made to use an already-rotated refresh token.revokeSession) and global logouts (revokeAllUserSessions).add_trusted_device) or unregisters (remove_trusted_device) a device fingerprint.4. Acceptance Criteria Checklist Met
SUCCESSorFAILUREstates.sessionIdto the log to track activity across a specific device's lifecycle.CorrelationLoggerService.getCorrelationId()to ensure auth events can be traced alongside upstream/downstream microservice logs.Testing & Verification
[REDACTED]properly replaces values in the request context when passing mock token data.AuthSessionService(including early throw catches) correctly emit an audit log before terminating.