Move auth tokens from localStorage to httpOnly cookies #24

Open
opened 2026-04-20 09:37:44 +00:00 by sharang · 0 comments
Owner

Problem

Auth tokens and tenant identifiers are stored in localStorage:

  • lib/sdk/academy/api-courses.ts stores authToken in localStorage
  • lib/sdk/dsr/api-types.ts reads X-User-ID and X-Tenant-ID from localStorage

localStorage is accessible to any JavaScript running on the page. An XSS vulnerability anywhere in the app allows an attacker to exfiltrate tokens and impersonate users.

Required Actions

  1. Move authToken to an httpOnly, Secure, SameSite=Strict cookie set by the backend on login
  2. Remove X-User-ID from frontend entirely — derive from JWT on the backend
  3. After #5 (tenant isolation fix): X-Tenant-ID is no longer needed on the frontend
  4. Update the frontend to rely on the cookie implicitly — no explicit token management in JS code
  5. Update CORS config (#8) to include allow_credentials=True with explicit origins

Acceptance Criteria

## Problem Auth tokens and tenant identifiers are stored in `localStorage`: - `lib/sdk/academy/api-courses.ts` stores `authToken` in localStorage - `lib/sdk/dsr/api-types.ts` reads `X-User-ID` and `X-Tenant-ID` from localStorage `localStorage` is accessible to any JavaScript running on the page. An XSS vulnerability anywhere in the app allows an attacker to exfiltrate tokens and impersonate users. ## Required Actions 1. Move `authToken` to an httpOnly, Secure, SameSite=Strict cookie set by the backend on login 2. Remove `X-User-ID` from frontend entirely — derive from JWT on the backend 3. After #5 (tenant isolation fix): `X-Tenant-ID` is no longer needed on the frontend 4. Update the frontend to rely on the cookie implicitly — no explicit token management in JS code 5. Update CORS config (#8) to include `allow_credentials=True` with explicit origins ## Acceptance Criteria - `localStorage` contains no token or tenant data - `document.cookie` does not show the auth token (httpOnly flag) - Authenticated API calls work via cookie without explicit `Authorization` header - Depends on: #4, #5, #8
sharang added this to the M5: Frontend Hardening milestone 2026-04-20 09:37:44 +00:00
sharang added the frontendsecurityseverity: medium labels 2026-04-20 09:37:45 +00:00
Sign in to join this conversation.