24 - Browser Security

Overview

OpenAlgo implements browser-side security measures including session management, CSRF protection, secure cookies, and content security policies.

Architecture Diagram

┌──────────────────────────────────────────────────────────────────────────────┐
│                       Browser Security Architecture                          │
└──────────────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────────────┐
│                           Security Layers                                    │
│                                                                              │
│  ┌─────────────────────────────────────────────────────────────────────┐   │
│  │  Layer 1: Session Security                                           │   │
│  │  - Session-based authentication                                      │   │
│  │  - Auto-expiry at 3 AM IST (configurable)                           │   │
│  │  - Token revocation on logout                                        │   │
│  └─────────────────────────────────────────────────────────────────────┘   │
│                                                                              │
│  ┌─────────────────────────────────────────────────────────────────────┐   │
│  │  Layer 2: Cookie Security                                            │   │
│  │  - Secure flag (HTTPS only)                                          │   │
│  │  - HttpOnly flag (no JS access)                                      │   │
│  │  - SameSite=Lax (CSRF protection)                                    │   │
│  └─────────────────────────────────────────────────────────────────────┘   │
│                                                                              │
│  ┌─────────────────────────────────────────────────────────────────────┐   │
│  │  Layer 3: Authentication Flow                                        │   │
│  │  - Argon2 password hashing                                           │   │
│  │  - TOTP support for 2FA                                              │   │
│  │  - Rate limiting on login                                            │   │
│  └─────────────────────────────────────────────────────────────────────┘   │
│                                                                              │
└─────────────────────────────────────────────────────────────────────────────┘

Session Management

Session Lifecycle

Session Expiry Configuration

Session Validation

Flag
Purpose

Secure

Only sent over HTTPS

HttpOnly

Cannot be read by JavaScript

SameSite=Lax

Prevents CSRF in most cases

Password Security

Argon2 Hashing

Password Requirements

Login Rate Limiting

Configuration

Implementation

TOTP Two-Factor Authentication

Setup Flow

TOTP Validation

Token Revocation

On Logout

On Session Expiry

React Frontend Security

API Key Handling

AJAX Request Detection

Security Headers

Session Storage

What's Stored

What's NOT Stored

  • Passwords (only hashes in DB)

  • API keys in session (encrypted in DB)

  • Auth tokens in session (encrypted in DB)

Credential Masking

Display Masking

Key Files Reference

File
Purpose

utils/session.py

Session management

utils/auth_utils.py

Auth utilities

database/user_db.py

User model

blueprints/auth.py

Auth routes

frontend/src/api/

Secure API calls

Last updated