tor-browser

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

tsn-ca.js (1603B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 /*
      8 * Bug 1802340 - tsn.ca login broken with dFPI enabled
      9 *
     10 * tsn.ca relies upon a login page that is out-of-origin. That login page
     11 * sets a cookie for https://www.tsn.ca, which is then used as an proof of
     12 * authentication on redirect back to the main site. This shim adds a request
     13 * for storage access for https://www.tsn.ca when the user tries to log in.
     14 */
     15 
     16 console.warn(
     17  `When logging in, Firefox calls the Storage Access API on behalf of the site. See https://bugzilla.mozilla.org/show_bug.cgi?id=1802340 for details.`
     18 );
     19 
     20 // Third-party origin we need to request storage access for.
     21 const STORAGE_ACCESS_ORIGIN = "https://www.tsn.ca";
     22 
     23 document.documentElement.addEventListener(
     24  "click",
     25  e => {
     26    const { target, isTrusted } = e;
     27    if (!isTrusted) {
     28      return;
     29    }
     30 
     31    const button = target.closest("button");
     32    if (!button) {
     33      return;
     34    }
     35    const form = target.closest(".login-form");
     36    if (!form) {
     37      return;
     38    }
     39 
     40    console.warn(
     41      "Calling the Storage Access API on behalf of " + STORAGE_ACCESS_ORIGIN
     42    );
     43    button.disabled = true;
     44    e.stopPropagation();
     45    e.preventDefault();
     46    document
     47      .requestStorageAccessForOrigin(STORAGE_ACCESS_ORIGIN)
     48      .then(() => {
     49        button.disabled = false;
     50        target.click();
     51      })
     52      .catch(() => {
     53        button.disabled = false;
     54      });
     55  },
     56  true
     57 );