Conversation
…lth#515) - Implement session anomaly service with location hop, device mutation, and subnet jump heuristics - Integrate anomaly evaluation into requireAuth middleware and rotateRefreshToken service - Trigger automatic session revocation, WebSocket termination, and security.session_anomaly event - Add comprehensive unit tests covering heuristics and protective workflows
|
@Gezziy 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 #515
Summary of Changes$O(1)$ heuristics: IMPOSSIBLE_LOCATION_HOP (location hop in < 15 mins), SUSPICIOUS_DEVICE_TYPE_CHANGE (mid-session shift to CLI or mismatched mobile OS), and SUBNET_JUMP_ANOMALY (IP jump across /16 subnets in < 60s).
Anomaly Detection Service (src/services/session-anomaly.service.ts):
Implemented detectSessionAnomaly evaluating three
Implemented evaluateAndHandleSessionAnomaly to execute session revocation, immediate WebSocket disconnection (closeUserSockets), and security event emission.
Middleware & Token Rotation Integration:
Updated requireAuth (
src/middleware/authenticate.ts
) to intercept suspicious requests with 401 Unauthorized (session_anomaly_detected).
Updated rotateRefreshToken (
src/services/refresh-token.service.ts
) to validate session context during token refresh.
Event Vocabulary (src/events/types.ts):
Registered security.session_anomaly under SOCKET_ONLY_EVENT_TYPES mapped to the alerts topic.
Unit Test Coverage (tests/unit/session-anomaly.test.ts):
Added unit test suite covering heuristic evaluations and forced logout flows.
Reason for Changes
To fulfill Issue #515, enhancing account security and mitigating risk of Session Hijacking and Account Takeover (ATO). Suspicious session activities now trigger immediate, standardized protective controls and security audit events.