Skip to content

Conversation

RonenMars
Copy link
Contributor

@RonenMars RonenMars commented Sep 11, 2025

Description

Overview

Complete refactor of the OAuth authentication system with comprehensive security improvements, error handling, and code quality enhancements.

🚀 Key Features

Security Enhancements

  • OAuth Redirect URL Validation: Added domain allowlist validation with HTTPS enforcement to prevent open redirect attacks
  • Secure Error Logging: All sensitive operations use structured logging with consoleOnly: true flag
  • Type Safety: Replaced all any types with proper TypeScript interfaces

Error Handling & Resilience

  • Retry Mechanism: Implemented exponential backoff retry logic for OAuth failures (3 attempts, 1000ms base delay)
  • Error Boundaries: Added React error boundaries specifically for OAuth components with fallback UI
  • Toast Notifications: User-friendly error messages with internationalization support

Code Quality Improvements

  • Logging Integration: Replaced all console statements with structured LoggerService calls
  • Configuration Constants: Extracted hardcoded values to configurable constants (oauthConfig, oauthRetryConfig)
  • Clean Architecture: Proper separation of concerns with dedicated utility functions and interfaces

🛡️ Security Features

OAuth Redirect Validation

export const oauthConfig = {
  allowedDomains: [
    "github.com",
    "api.github.com", 
    "accounts.google.com",
    "login.microsoftonline.com",
    "oauth.descope.com",
    "api.descope.com",
  ] as const,
  protocol: "https:",
} as const;

Error Boundary Protection

  • Comprehensive error catching for OAuth component failures
  • Graceful fallback UI with retry and navigation options
  • Structured error logging for debugging

🔄 Retry Mechanism

export const oauthRetryConfig = {
  maxAttempts: 3,
  baseDelayMs: 1000,
} as const;
  • Exponential backoff: 1s, 2s, 3s delays between retries
  • Automatic retry for network failures and temporary OAuth errors
  • User-friendly error messages after all retries are exhausted

Impact: This refactor significantly improves the security, reliability, and maintainability of the OAuth authentication system while maintaining backward compatibility.

Linear Ticket

https://linear.app/autokitteh/issue/UI-1841/reduce-login-screen-flash-after-successful-authentication

What type of PR is this? (check all applicable)

  • 💡 (feat) - A new feature (non-breaking change which adds functionality)
  • 🔄 (refactor) - Code Refactoring - A code change that neither fixes a bug nor adds a feature
  • 🐞 (fix) - Bug Fix (non-breaking change which fixes an issue)
  • 🏎 (perf) - Optimization
  • 📄 (docs) - Documentation - Documentation only changes
  • 📄 (test) - Tests - Adding missing tests or correcting existing tests
  • 🎨 (style) - Styles - Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  • ⚙️ (ci) - Continuous Integrations - Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
  • ☑️ (chore) - Chores - Other changes that don't modify src or test files
  • ↩️ (revert) - Reverts - Reverts a previous commit(s).

@RonenMars RonenMars force-pushed the ronen/refactor/login-page branch from 86eb47e to 0f2439e Compare September 15, 2025 10:17
@RonenMars RonenMars changed the title refactor: login handler refactor(UI-1841): login handler Sep 15, 2025
@RonenMars RonenMars changed the title refactor(UI-1841): login handler feat(UI-1841): enhance login security with OAuth improvements and token encryption Sep 26, 2025
This reverts commit ed3cd2f.
- Remove all console.log statements from OAuth login flow
- Add .serena/ to .gitignore for AI IDE configuration
- Replace console statements with LoggerService calls using consoleOnly flag
- Add OAuth error message translation for user-friendly error handling
- Add toast notifications for OAuth login errors
- Update 404 pages to use structured logging
- Clean up debug console statements in chatbot iframe components
- Add validateOAuthRedirectURL utility function with domain allowlist
- Enforce HTTPS requirement for all OAuth redirect URLs
- Validate OAuth provider domains against security allowlist
- Integrate URL validation into login component OAuth flow
- Add comprehensive logging for security validation events

Security improvements:
- Prevent open redirect vulnerabilities
- Restrict OAuth flows to trusted provider domains
- Add runtime validation with detailed error logging
- Added proper OAuthResponse interface for OAuth callback handling
- Fixed LoggerService calls to use correct parameter format
- Updated TypeScript types for better type safety
- Removed invalid Toast.title property usage
- Added exponential backoff retry logic for OAuth start failures
- Configurable retry attempts (3) and base delay (1000ms)
- Comprehensive error logging with structured messages
- Proper error handling with user-friendly toast notifications
- Created oauthConfig with allowed domains and protocol constants
- Improved code maintainability and configuration management
- Consistent camelCase naming convention for better TypeScript compliance
- Centralized OAuth security configuration
- Implement AES-GCM encryption for sensitive localStorage data using Web Crypto API
- Replace clear text storage of API tokens with encrypted storage
- Update localStorage utilities to support async encryption/decryption
- Add request interceptors to dynamically decrypt tokens for authentication
- Update affected components to handle async token operations
  - Maintain backward compatibility with fallback mechanisms

Resolves CodeQL security warning for clear text storage of sensitive information.
@RonenMars RonenMars force-pushed the ronen/refactor/login-page branch from dd6dc7e to e2bbe43 Compare September 26, 2025 23:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant