tor-browser

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

session-storage.tentative.https.window.js (2128B)


      1 // META: script=/common/get-host-info.sub.js
      2 // META: script=/common/utils.js
      3 // META: script=/common/dispatcher/dispatcher.js
      4 // META: script=/html/cross-origin-embedder-policy/credentialless/resources/common.js
      5 // META: script=./resources/common.js
      6 
      7 // Make |iframe| to store |key|=|value| into sessionStorage.
      8 const store = async (iframe, key, value) => {
      9  const response_queue = token();
     10  send(iframe, `
     11    sessionStorage.setItem("${key}", "${value}");
     12    send("${response_queue}", "stored");
     13  `);
     14  assert_equals(await receive(response_queue), "stored");
     15 };
     16 
     17 // Make |iframe| to load |key| in sessionStorage. Check it matches the
     18 // |expected_value|.
     19 const load = async (iframe, key, expected_value) => {
     20  const response_queue = token();
     21  send(iframe, `
     22    const value = sessionStorage.getItem("${key}");
     23    send("${response_queue}", value || "not found");
     24  `);
     25  assert_equals(await receive(response_queue), expected_value);
     26 };
     27 
     28 promise_test(async test => {
     29  const origin = get_host_info().HTTPS_REMOTE_ORIGIN;
     30  const key_1 = token();
     31  const key_2 = token();
     32 
     33  // 4 actors: 2 credentialless iframe and 2 normal iframe.
     34  const iframe_credentialless_1 = newIframeCredentialless(origin);
     35  const iframe_credentialless_2 = newIframeCredentialless(origin);
     36  const iframe_normal_1 = newIframe(origin);
     37  const iframe_normal_2 = newIframe(origin);
     38 
     39  // 1. Store a value in one credentialless iframe and one normal iframe.
     40  await Promise.all([
     41    store(iframe_credentialless_1, key_1, "value_1"),
     42    store(iframe_normal_1, key_2, "value_2"),
     43  ]);
     44 
     45  // 2. Check what each of them can retrieve.
     46  await Promise.all([
     47    load(iframe_credentialless_1, key_1, "value_1"),
     48    load(iframe_credentialless_2, key_1, "value_1"),
     49    load(iframe_credentialless_1, key_2, "not found"),
     50    load(iframe_credentialless_2, key_2, "not found"),
     51 
     52    load(iframe_normal_1, key_1, "not found"),
     53    load(iframe_normal_2, key_1, "not found"),
     54    load(iframe_normal_1, key_2, "value_2"),
     55    load(iframe_normal_2, key_2, "value_2"),
     56  ]);
     57 }, "Session storage is correctly partitioned with regards to credentialless iframe");