Clear-Site-Data
The Clear-Site-Data header is a powerful security mechanism that allows a web server to request the browser to clear browsing data (like cookies, storage, and cache) associated with the requesting website.
How Clear-Site-Data Works
When a user logs out of a web application, simply deleting the session cookie on the server is often not enough. Data might still linger in the browser's localStorage, sessionStorage, IndexedDB, or cache. If a device is shared, this lingering data can pose a security or privacy risk.
By sending the Clear-Site-Data header during a logout request, the server guarantees that the browser locally scrubs the specified data types.
Basic Example
Clear-Site-Data: "cache", "cookies", "storage"
This policy dictates that the browser must delete:
- "cache": The browser cache for the origin.
- "cookies": All cookies for the origin.
- "storage": DOM storage (localStorage, sessionStorage, IndexedDB, etc.).
Common Pitfalls
Use this header with extreme caution on global responses. It should typically only be sent on explicit logout endpoints. If you send Clear-Site-Data: "cookies" on every page load, users will be instantly logged out upon every request.
Check Your Header
Use the SecurityHeaders.nl scanner to verify if your application correctly implements modern HTTP security standards.