Course contentsShow
← Security
Lesson 1079 of 3,05222. Web Security - Client-Side and SPA SecurityFree lesson

Storage Quota and Eviction Policies

Understanding browser storage limits, eviction strategies, and security implications of storage pressure and data persistence.

Storage Quota and Eviction Policies

What you'll learn: How browser storage limits and eviction behaviors can create security and reliability risks in client-side applications.

Why Storage Limits Matter for Security

Browsers don't give web applications unlimited storage space. Each origin receives a storage quota (typically 50-100 MB for temporary storage, more for persistent), and when that limit is reached, the browser must decide what to evict. Understanding these policies is critical because:

  • Data loss attacks: An attacker can fill your origin's storage with garbage data, forcing the browser to evict legitimate user data
  • Persistence expectations: Sensitive data you thought was safely stored may vanish unexpectedly
  • Resource exhaustion: Malicious scripts can attempt storage-based denial-of-service

Storage Pressure and Eviction Strategies

Browsers classify storage into two categories:

Temporary (best effort) - Default mode for localStorage, sessionStorage, IndexedDB, and Cache API. The browser can evict this data when disk space runs low, typically using LRU (Least Recently Used) policies.

Persistent - Data marked via the Storage API (navigator.storage.persist()) that browsers will only evict if the user manually clears it. Not all browsers honor persistence requests.

Think of it like a hotel: temporary guests get evicted when rooms are needed, but permanent residents have guaranteed space.

Security Implications

If your application stores authentication tokens, offline data, or encryption keys in client storage, you must account for:

  • Quota exhaustion attacks where malicious code fills storage to trigger eviction
  • Lost sensitive data if you rely on temporary storage for security-critical information
  • Broken offline functionality when eviction happens mid-session

Always check navigator.storage.estimate() to monitor available quota and handle QuotaExceededError gracefully. For critical data, request persistent storage and implement server-side backup mechanisms.

Key Takeaway: Browser storage quotas and eviction policies mean client-side data is never guaranteed—design security controls assuming storage can be exhausted or wiped, and never rely solely on client storage for authentication or sensitive state.