tor-browser

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

allowed-refresh-initiators.https.html (2492B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <script src="/common/get-host-info.sub.js"></script>
      6 <script src="helper.js" type="module"></script>
      7 
      8 <script type="module">
      9  import { expireCookie, documentHasCookie, waitForCookie, addCookieAndSessionCleanup, setupShardedServerState, configureServer, crossSiteFetch } from "./helper.js";
     10 
     11  async function runTest(t, origin, refresh_expected) {
     12    await setupShardedServerState({crossSite: true});
     13    const expectedCookieAndValue = "auth_cookie=abcdef0123";
     14    // Override the attributes to be SameSite=None.
     15    const expectedCookieAttributes = `Domain=${location.hostname};Path=/device-bound-session-credentials;SameSite=None;Secure`;
     16    const expectedCookieAndAttributes = `${expectedCookieAndValue};${expectedCookieAttributes}`;
     17    addCookieAndSessionCleanup(t);
     18 
     19    await configureServer({ allowedRefreshInitiators: [get_host_info().NOTSAMESITE_HOST],
     20                      cookieDetails: [ {attributes: expectedCookieAttributes} ],
     21                    });
     22 
     23    // Prompt starting a session, and wait until registration completes.
     24    const loginResponse = await fetch('login.py');
     25    assert_equals(loginResponse.status, 200);
     26    await waitForCookie(expectedCookieAndValue, /*expectCookie=*/true);
     27 
     28    // Expire the cookie, and check whether a refresh has occurred.
     29    expireCookie(expectedCookieAndAttributes);
     30    assert_false(documentHasCookie(expectedCookieAndValue));
     31 
     32    const authStatusAfterExpiry = await crossSiteFetch(origin, `${location.origin}/device-bound-session-credentials/verify_authenticated.py`, {credentials: "include"});
     33    assert_equals(authStatusAfterExpiry, refresh_expected ? 200 : 403);
     34    assert_equals(documentHasCookie(expectedCookieAndValue), refresh_expected);
     35  }
     36 
     37  promise_test(async t => {
     38    await runTest(t, location.origin, /*refresh_expected=*/true);
     39  }, "An established session refreshes when initated by the owning site");
     40 
     41  promise_test(async t => {
     42    await runTest(t, get_host_info().HTTPS_NOTSAMESITE_ORIGIN, /*refresh_expected=*/true);
     43  }, "An established session refreshes when initated by a host in allowed_refresh_initiators");
     44 
     45  promise_test(async t => {
     46    await runTest(t, get_host_info().HTTPS_OTHER_NOTSAMESITE_ORIGIN, /*refresh_expected=*/false);
     47  }, "An established session does not refresh when initated by a host not in allowed_refresh_initiators");
     48 </script>