feat: Comprehensive Authentication & Authorization Hardening#3
Open
devin-ai-integration[bot] wants to merge 3 commits intomasterfrom
Open
feat: Comprehensive Authentication & Authorization Hardening#3devin-ai-integration[bot] wants to merge 3 commits intomasterfrom
devin-ai-integration[bot] wants to merge 3 commits intomasterfrom
Conversation
- Add JWT refresh token rotation with RefreshTokenEntity and RefreshTokenService - Implement token blacklisting system with BlacklistedTokenEntity and TokenBlacklistService - Enhance password security with stronger validation rules (8+ chars, uppercase, lowercase, number, special char) - Add password history tracking with PasswordHistoryEntity to prevent reuse of last passwords - Implement session management with UserSessionEntity and device fingerprinting - Add account lockout mechanism with progressive delays after failed login attempts - Increase bcrypt salt rounds from 10 to 12 for stronger password hashing - Create database migration for new tables: refresh_tokens, blacklisted_tokens, password_history, user_sessions - Add new columns to users_auth table: failed_login_attempts, locked_until, last_password_change - Implement EnhancedJwtAuthGuard with token blacklist checking - Add TokenBlacklistMiddleware for request-level token validation - Create AuthCleanupCron for automated cleanup of expired tokens and sessions - Update JWT configuration for shorter access token expiration (30 minutes) - Add new authentication endpoints: refresh token, session management (list/revoke sessions) - Enhance auth controller with device info tracking and session management - Follow NestJS best practices and TypeORM patterns throughout implementation Co-Authored-By: Arthur Poon <arthur.poon@windsurf.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
…tion errors - Add @CreateDateColumn and @UpdateDateColumn to all new entities - Fix PasswordHistoryService TypeORM query syntax - Add missing session management methods to UserService - Resolve all TypeORM compilation errors for authentication hardening Co-Authored-By: Arthur Poon <arthur.poon@windsurf.com>
- Add new repositories and services to UserModule exports and providers - Import RefreshTokenService and TokenBlacklistService in AuthModule - Add TypeORM feature imports for new repositories - Resolve dependency injection errors for authentication services Co-Authored-By: Arthur Poon <arthur.poon@windsurf.com>
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.
Authentication & Authorization Hardening Implementation
Summary
This PR implements comprehensive authentication and authorization hardening for the NestJS banking application, including JWT refresh token rotation, token blacklisting, enhanced password security, account lockout mechanisms, and session management.
Key Features Added:
Database Changes:
refresh_tokens,blacklisted_tokens,password_history,user_sessionsusers_authtable with security fieldsReview & Testing Checklist for Human
Recommended Test Plan:
Diagram
%%{ init : { "theme" : "default" }}%% graph TB subgraph "Authentication Flow" AuthController["auth/controllers/<br/>auth.controller.ts"]:::major-edit AuthService["auth/services/<br/>auth.service.ts"]:::major-edit RefreshTokenService["auth/services/<br/>refresh-token.service.ts"]:::major-edit TokenBlacklistService["auth/services/<br/>token-blacklist.service.ts"]:::major-edit end subgraph "User Management" UserService["user/services/<br/>user.service.ts"]:::minor-edit PasswordHistoryService["user/services/<br/>password-history.service.ts"]:::major-edit SessionManagementService["user/services/<br/>session-management.service.ts"]:::major-edit end subgraph "Database Layer" RefreshTokenEntity["user/entities/<br/>refresh-token.entity.ts"]:::major-edit BlacklistedTokenEntity["user/entities/<br/>blacklisted-token.entity.ts"]:::major-edit PasswordHistoryEntity["user/entities/<br/>password-history.entity.ts"]:::major-edit UserSessionEntity["user/entities/<br/>user-session.entity.ts"]:::major-edit UserAuthEntity["user/entities/<br/>user-auth.entity.ts"]:::minor-edit end subgraph "Configuration" AuthModule["auth/index.ts"]:::minor-edit UserModule["user/index.ts"]:::minor-edit Migration["migrations/<br/>auth-hardening.ts"]:::major-edit end AuthController --> AuthService AuthService --> RefreshTokenService AuthService --> TokenBlacklistService AuthService --> PasswordHistoryService AuthService --> SessionManagementService RefreshTokenService --> RefreshTokenEntity TokenBlacklistService --> BlacklistedTokenEntity PasswordHistoryService --> PasswordHistoryEntity SessionManagementService --> UserSessionEntity AuthModule --> AuthService UserModule --> UserService subgraph Legend L1[Major Edit]:::major-edit L2[Minor Edit]:::minor-edit L3[Context/No Edit]:::context end classDef major-edit fill:#90EE90 classDef minor-edit fill:#87CEEB classDef context fill:#FFFFFFNotes
Security Enhancements:
Performance Considerations:
Link to Devin run: https://app.devin.ai/sessions/5f952db1308d403a9bbc679cc1c3de7a
Requested by: Arthur Poon (@akkp-windsurf)