Skip to content

[EPIC] Security: Migrate authentication from localStorage to httpOnly cookies #208

@kevalyq

Description

@kevalyq

🗺️ EPIC: httpOnly Cookie Authentication Migration

Original Issue: Closes #205
Priority: High
Area: Authentication, Security

Goal

Replace insecure localStorage token storage with httpOnly cookie-based authentication using Laravel Sanctum SPA mode to protect against XSS attacks.

Sub-Issues & Work Plan

Backend (api repo)

Frontend (frontend repo)

Technical Context

Current State (Insecure):

// Frontend stores token in localStorage
localStorage.setItem('auth_token', token);
// Vulnerable to XSS attacks

Target State (Secure):

// Backend sends httpOnly cookie
// Frontend uses credentials: 'include'
fetch(url, { credentials: 'include' });
// Token inaccessible to JavaScript

Dependencies

Backend must implement first:

  1. Laravel Sanctum SPA authentication mode
  2. SANCTUM_STATEFUL_DOMAINS configuration
  3. CORS configuration with credentials: true
  4. CSRF token endpoint (/sanctum/csrf-cookie)

Frontend follows:

  1. Remove localStorage token storage
  2. Update fetch calls to use credentials: 'include'
  3. Add CSRF token handling
  4. Update AuthContext

Acceptance Criteria

  • Backend: Sanctum SPA mode configured
  • Backend: CORS allows credentials from frontend domain
  • Backend: CSRF protection enabled
  • Frontend: No token accessible via JavaScript
  • Frontend: All auth requests include cookies
  • Tests: Auth flow works end-to-end
  • Tests: CSRF protection validated
  • Docs: Migration guide for developers

References

Non-Goals

  • Mobile app authentication (different flow)
  • API token management (separate concern)
  • Session storage (using Sanctum cookies)

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestsecuritySecurity-related changes or vulnerabilities

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions