tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

storage-access-beyond-cookies.caches.sub.https.window.js (1815B)


      1 // META: script=/resources/testdriver.js
      2 // META: script=/resources/testdriver-vendor.js
      3 
      4 'use strict';
      5 
      6 // Here's the set-up for this test:
      7 // Step 1 (top-frame) Set up listener for "HasAccess" message.
      8 // Step 2 (top-frame) Write first-party cache storage.
      9 // Step 3 (top-frame) Embed an iframe that's cross-site with top-frame.
     10 // Step 4 (sub-frame) Try to use storage access API and read first-party data.
     11 // Step 5 (sub-frame) Embed an iframe that's same-origin with top-frame.
     12 // Step 6 (sub-sub-frame) Try to use storage access API and read first-party data.
     13 // Step 7 (sub-sub-frame) Send "HasAccess for caches" message to top-frame.
     14 // Step 8 (top-frame) Receive "HasAccess for caches" message and cleanup.
     15 
     16 async_test(t => {
     17  // Step 1
     18  window.addEventListener("message", t.step_func((e) => {
     19    if (e.data.type != "result") {
     20      return;
     21    }
     22    // Step 8
     23    assert_equals(e.data.message, "HasAccess for caches", "Storage Access API should be accessible and return first-party data");
     24    t.add_cleanup(() => {test_driver.delete_all_cookies();});
     25    t.done();
     26  }));
     27 
     28  // Step 2
     29  const id = Date.now();
     30  document.cookie = "samesite_strict=test; SameSite=Strict; Secure";
     31  document.cookie = "samesite_lax=test; SameSite=Lax; Secure";
     32  document.cookie = "samesite_none=test; SameSite=None; Secure";
     33 
     34  window.caches.open(id).then(async (cache) => {
     35    await cache.add("https://{{hosts[][]}}:{{ports[https][0]}}/storage-access-api/resources/get_cookies.py?1");
     36    // Step 3
     37    let iframe = document.createElement("iframe");
     38    iframe.src = "https://{{hosts[alt][]}}:{{ports[https][0]}}/storage-access-api/resources/storage-access-beyond-cookies-iframe.sub.html?type=caches&id="+id;
     39    document.body.appendChild(iframe);
     40  });
     41 }, "Verify StorageAccessAPIBeyondCookies for Cache Storage");