- Add Session Tokens to Database (Primary Defense)
- Store cryptographically random session token (128-bit minimum)
- Regenerate on login, password change, privilege escalation
- Validate both user_id AND session_token on every request
- Implements token denylist pattern for immediate revocation
- Session Rotation on Login (Session Fixation Protection)
- Generate new session ID after authentication
- Invalidate old session tokens
- OWASP Session Fixation Protection
- Add Security Audit Fields
- Track session creation time, last activity, IP address, user agent
- Detect suspicious activity (IP changes, concurrent sessions)
- Enable forensic analysis
- Implement "Logout All Sessions"
- Allow users to invalidate all sessions globally
- Critical for compromised account recovery
- Use UUIDs for User IDs (Defense in Depth)
- Replace sequential integers with UUIDs
- Prevents user enumeration attacks
- Users table uses UUID (TEXT PRIMARY KEY)
- Session fields:
session_token,session_created_at,session_last_activity,session_ip,session_user_agent - All foreign keys updated from INTEGER to TEXT
File: internal/framework/auth/security.go
GenerateUUID()- UUID v4 for user IDsGenerateSessionToken()- 128-bit cryptographic session tokenGenerateCSRFToken()- 256-bit CSRF token
File: internal/framework/database/users.go
SetUserSessionToken(userID, token, ip, userAgent)- Store session on loginValidateSessionToken(userID, token)- Validate on every requestClearUserSessionToken(userID)- Invalidate on logout/password changeClearAllUserSessions(userID)- "Logout all devices"GetUserSessionInfo(userID)- Audit session metadata
File: internal/framework/auth/auth.go
Login() - Generates 128-bit session token, stores in database and cookie
GetUser() - Validates session token from cookie against database (CRITICAL SECURITY)
Logout() - Clears session token from database and invalidates cookie
ChangePassword() - Invalidates session token, forces re-authentication
To verify the security fix:
- Delete database:
rm -f data/*.db* - Start server:
make dev-local - Log in and save cookie
- Stop server, delete database, restart
- Try to access with old cookie - should FAIL ✅
✅ Session ID Properties (128-bit cryptographic)
✅ Server-side Validation (database-backed tokens)
✅ Session Rotation (on login/password change)
✅ Immediate Revocation (logout/password change)
✅ Session Metadata (IP, User-Agent for anomaly detection)
✅ UUID User IDs (prevents enumeration)