Safari ITP Storage Eviction and Client-Side Cookie Persistence
0 reputation · 16 May 2022, 13:50 UTC
0 reputation · 16 May 2022, 13:50 UTC
Safari employs Intelligent Tracking Prevention (ITP) to limit the persistence of client-side storage. A documented behavior involves a 7-day cap on the expiration of cookies set via document.cookie, regardless of the specified Max-Age or Expires attributes.
There is a distinction between cookies set via HTTP response headers and those set programmatically. Furthermore, Safari implements a purge mechanism that evicts storage for domains that have not seen user interaction within a specific window.
It is unclear if programmatic updates to storage, performed without a direct user-initiated event, are sufficient to reset the 7-day eviction timer for that domain.
localStorage or document.cookie reset the ITP eviction clock?30275 reputation · 16 May 2022, 18:15 UTC
No, programmatic updates to localStorage or document.cookie do not reset the Intelligent Tracking Prevention (ITP) eviction clock. Safari distinguishes between automated script execution and genuine user engagement to prevent sites from artificially extending their storage lifespan through background scripts or automated refreshes.
document.cookie are capped at a 7-day expiration, regardless of the Max-Age or Expires attributes provided.Set-Cookie) are generally exempt from this 7-day programmatic cap and can persist longer.localStorage and IndexedDB are subject to deletion if the user does not interact with the domain for a specific period (typically 7 days).Safari's ITP is designed to combat "fingerprinting" and persistent tracking. If a script could reset the eviction timer simply by writing a value to storage, any site with a background worker or a frequent redirect could maintain a permanent identifier without the user ever returning to the site. Consequently, the "clock" is tied to User Interaction, not Storage Mutation.
To extend the persistence of first-party storage beyond the default caps, the user must perform a direct interaction. While Apple does not publish a comprehensive list of "qualifying events," the following generally trigger a reset of the interaction window:
To verify these constraints in your specific Safari version:
document.cookie with a 30-day Max-Age.Diagnostic Detail Needed: Are you observing this eviction in a first-party context (the domain in the address bar) or a third-party context (an iframe or API call)? ITP rules are significantly more aggressive for third-party storage.
Use comments to ask for clarification. Post a solution as an answer.
30,275 reputation · 16 May 2022, 19:52 UTC
Important nuance: the ITP‑driven 7‑day expiration is refreshed only by a user‑initiated top‑level navigation (e.g., a click that changes the URL or a form submission that causes a full page load). In‑page actions such as focusing an input, scrolling, or dispatching synthetic events do not reset the timer, even though they may count as user interaction for other APIs. Consequently, a script that merely updates document.cookie or localStorage without triggering a navigation cannot extend the storage lifetime beyond the default cap.