[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [Git][tpo/applications/tor-browser][tor-browser-115.4.0esr-13.5-1] fixup! Bug 42019: Empty browser's clipboard on browser shutdown



Title: GitLab

richard pushed to branch tor-browser-115.4.0esr-13.5-1 at The Tor Project / Applications / Tor Browser

Commits:

  • ef3a546d
    by hackademix at 2023-10-18T21:46:03+02:00
    fixup! Bug 42019: Empty browser's clipboard on browser shutdown
    
    Bug 42154: empty clipboard content from private windows on exit.
    

2 changed files:

Changes:

  • browser/app/profile/001-base-profile.js
    ... ... @@ -87,6 +87,9 @@ pref("browser.sessionstore.resume_from_crash", false);
    87 87
     // Also not needed in PBM at the moment.
    
    88 88
     pref("browser.pagethumbnails.capturing_disabled", true);
    
    89 89
     
    
    90
    +// Empty clipboard content from private windows on exit (tor-browser#42154)
    
    91
    +pref("browser.privatebrowsing.preserveClipboard", false);
    
    92
    +
    
    90 93
     // Enable HTTPS-Only mode (tor-browser#19850)
    
    91 94
     pref("dom.security.https_only_mode", true);
    
    92 95
     // The previous pref automatically sets this to true (see StaticPrefList.yaml),
    

  • browser/components/BrowserGlue.sys.mjs
    ... ... @@ -150,6 +150,119 @@ const PRIVATE_BROWSING_EXE_ICON_INDEX = 1;
    150 150
     const PREF_PRIVATE_BROWSING_SHORTCUT_CREATED =
    
    151 151
       "browser.privacySegmentation.createdShortcut";
    
    152 152
     
    
    153
    +// Empty clipboard content from private windows on exit
    
    154
    +// (tor-browser#42154)
    
    155
    +const ClipboardPrivacy = {
    
    156
    +  _lastClipboardHash: null,
    
    157
    +  _globalActivation: false,
    
    158
    +  _isPrivateClipboard: false,
    
    159
    +  _hasher: null,
    
    160
    +
    
    161
    +  _computeClipboardHash(win = Services.ww.activeWindow) {
    
    162
    +    const trans = Cc["@mozilla.org/widget/transferable;1"].createInstance(
    
    163
    +      Ci.nsITransferable
    
    164
    +    );
    
    165
    +    trans.init(win?.docShell?.QueryInterface(Ci.nsILoadContext) || null);
    
    166
    +    ["text/x-moz-url", "text/plain"].forEach(trans.addDataFlavor);
    
    167
    +    try {
    
    168
    +      Services.clipboard.getData(trans, Ci.nsIClipboard.kGlobalClipboard);
    
    169
    +      const clipboardContent = {};
    
    170
    +      trans.getAnyTransferData({}, clipboardContent);
    
    171
    +      const { data } = clipboardContent.value.QueryInterface(
    
    172
    +        Ci.nsISupportsString
    
    173
    +      );
    
    174
    +      const bytes = new TextEncoder().encode(data);
    
    175
    +      const hasher = (this._hasher ||= Cc[
    
    176
    +        "@mozilla.org/security/hash;1"
    
    177
    +      ].createInstance(Ci.nsICryptoHash));
    
    178
    +      hasher.init(hasher.SHA256);
    
    179
    +      hasher.update(bytes, bytes.length);
    
    180
    +      return hasher.finish(true);
    
    181
    +    } catch (e) {}
    
    182
    +    return null;
    
    183
    +  },
    
    184
    +
    
    185
    +  startup() {
    
    186
    +    this._lastClipboardHash = this._computeClipboardHash();
    
    187
    +
    
    188
    +    // Here we track changes in active window / application,
    
    189
    +    // by filtering focus events and window closures.
    
    190
    +    const handleActivation = (win, activation) => {
    
    191
    +      if (activation) {
    
    192
    +        if (!this._globalActivation) {
    
    193
    +          // focus changed within this window, bail out.
    
    194
    +          return;
    
    195
    +        }
    
    196
    +        this._globalActivation = false;
    
    197
    +      } else if (!Services.focus.activeWindow) {
    
    198
    +        // focus is leaving this window:
    
    199
    +        // let's track whether it remains within the browser.
    
    200
    +        lazy.setTimeout(() => {
    
    201
    +          this._globalActivation = !Services.focus.activeWindow;
    
    202
    +        }, 100);
    
    203
    +      }
    
    204
    +      const clipboardHash = this._computeClipboardHash(win);
    
    205
    +      if (clipboardHash !== this._lastClipboardHash) {
    
    206
    +        this._isPrivateClipboard =
    
    207
    +          !activation &&
    
    208
    +          (lazy.PrivateBrowsingUtils.permanentPrivateBrowsing ||
    
    209
    +            lazy.PrivateBrowsingUtils.isWindowPrivate(win));
    
    210
    +        this._lastClipboardHash = clipboardHash;
    
    211
    +        console.log(
    
    212
    +          `Clipboard changed: private ${this._isPrivateClipboard}, hash ${clipboardHash}.`
    
    213
    +        );
    
    214
    +      }
    
    215
    +    };
    
    216
    +    const focusListener = e =>
    
    217
    +      e.isTrusted && handleActivation(e.currentTarget, e.type === "focusin");
    
    218
    +    const initWindow = win => {
    
    219
    +      for (const e of ["focusin", "focusout"]) {
    
    220
    +        win.addEventListener(e, focusListener);
    
    221
    +      }
    
    222
    +    };
    
    223
    +    for (const w of Services.ww.getWindowEnumerator()) {
    
    224
    +      initWindow(w);
    
    225
    +    }
    
    226
    +    Services.ww.registerNotification((win, event) => {
    
    227
    +      switch (event) {
    
    228
    +        case "domwindowopened":
    
    229
    +          initWindow(win);
    
    230
    +          break;
    
    231
    +        case "domwindowclosed":
    
    232
    +          handleActivation(win, false);
    
    233
    +          if (
    
    234
    +            this._isPrivateClipboard &&
    
    235
    +            lazy.PrivateBrowsingUtils.isWindowPrivate(win) &&
    
    236
    +            !(
    
    237
    +              lazy.PrivateBrowsingUtils.permanentPrivateBrowsing ||
    
    238
    +              Array.from(Services.ww.getWindowEnumerator()).find(w =>
    
    239
    +                lazy.PrivateBrowsingUtils.isWindowPrivate(w)
    
    240
    +              )
    
    241
    +            )
    
    242
    +          ) {
    
    243
    +            // no more private windows, empty private content if needed
    
    244
    +            this.emptyPrivate();
    
    245
    +          }
    
    246
    +      }
    
    247
    +    });
    
    248
    +  },
    
    249
    +  emptyPrivate() {
    
    250
    +    if (
    
    251
    +      this._isPrivateClipboard &&
    
    252
    +      !Services.prefs.getBoolPref(
    
    253
    +        "browser.privatebrowsing.preserveClipboard",
    
    254
    +        false
    
    255
    +      ) &&
    
    256
    +      this._lastClipboardHash === this._computeClipboardHash()
    
    257
    +    ) {
    
    258
    +      Services.clipboard.emptyClipboard(Ci.nsIClipboard.kGlobalClipboard);
    
    259
    +      this._lastClipboardHash = null;
    
    260
    +      this._isPrivateClipboard = false;
    
    261
    +      console.log("Private clipboard emptied.");
    
    262
    +    }
    
    263
    +  },
    
    264
    +};
    
    265
    +
    
    153 266
     /**
    
    154 267
      * Fission-compatible JSProcess implementations.
    
    155 268
      * Each actor options object takes the form of a ProcessActorOptions dictionary.
    
    ... ... @@ -1753,6 +1866,8 @@ BrowserGlue.prototype = {
    1753 1866
     
    
    1754 1867
         lazy.TorProviderBuilder.firstWindowLoaded();
    
    1755 1868
     
    
    1869
    +    ClipboardPrivacy.startup();
    
    1870
    +
    
    1756 1871
         this._firstWindowTelemetry(aWindow);
    
    1757 1872
         this._firstWindowLoaded();
    
    1758 1873
     
    
    ... ... @@ -2013,7 +2128,7 @@ BrowserGlue.prototype = {
    2013 2128
               lazy.UpdateListener.reset();
    
    2014 2129
             }
    
    2015 2130
           },
    
    2016
    -      () => Services.clipboard.emptyClipboard(Ci.nsIClipboard.kGlobalClipboard), // tor-browser#42019
    
    2131
    +      () => ClipboardPrivacy.emptyPrivate(), // tor-browser#42019
    
    2017 2132
           () => lazy.OnionAliasStore.uninit(),
    
    2018 2133
         ];
    
    2019 2134
     
    

  • _______________________________________________
    tor-commits mailing list
    tor-commits@xxxxxxxxxxxxxxxxxxxx
    https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits