Limiting Cookie Usage within iframe

Image 1 Image 2 Image 3 Image 4
Here we see a cookie addict having more fun in a sandbox than he expected - iSac, Gemini, January 28, 2025.

Browser Storage Sandbox Testing

Go straight to test.

IFrame sandbox and credentialless Attributes

Chromium (and maybe webkit? (update: sadly seems no) based browsers offer some features that allow the creator of an iframe to sandbox any code running in it. Two of those features are controlled via the sandbox and credentialless attributes. The sandbox attribute controls client side activity, such as whether to allow the iframe to access cookies via JS, allow popups, and other interactions. The credentialless attribute controls access to local storage and sending of credentials on requests from the frame. In paritcular all storage is partitioned by an additional nonce that is allocated per origin per page load.

This is valuable in cases where a page-owner wants to allow third party content to be loaded into a frame, but limit interactions with the user and sandbox the code in frame.

Demo Overview

Below you can self-demo this functionality with different options. The test involves an endpoint returning content to an iframe, and in its resposne setting a cookie. You can control the attributes on the iframe and origin of the request, which will let you explore how cookie persistence is impacted by different settings.

The form will reload this page with the selections as query params, at which point the load handler will:

  1. Clear the cookies for each of the available domains.
  2. Load an iframe with the "set-cookie" endpoint as its src
  3. That endpoint returns "content" describing the request it saw, including cookies, and also includes a set-cookie header.
  4. After (2) completes, there will be a second load to the same endpoint, as well as a second page open that loads the "content" showing what cookies the endpoint sees.

You should expect to see the cookie for the second frame on page, but not for the second page load.

Demo

The form below allows you to set up several parameters for:

Options












Results