Ticket #22084: 0001-Spoofing-network-information-API-and-blocking-ontype.patch

File 0001-Spoofing-network-information-API-and-blocking-ontype.patch, 4.1 KB (added by igt0, 18 months ago)

Version 1 - Backport commits from firefox

  • browser/components/resistfingerprinting/test/browser/browser.ini

    From 5c3aa79f5f75419da75fef4e87333591458a80ce Mon Sep 17 00:00:00 2001
    From: Igor Oliveira <igor.oliveira@posteo.net>
    Date: Mon, 11 Dec 2017 14:07:56 -0200
    Subject: [PATCH] Spoofing network information API and blocking ontypechange
     event when 'privacy.resistFingerprinting' is true. r=arthuredelstein,baku
    
    This patch makes the network information API always returns the default type 'unknown'
    and blocking the ontypechange event while connection type changed when 'privacy.
    resistFingerprinting' is true.
    
    MozReview-Commit-ID: 4eOdHgAGtyY
    
    This adds a test case to test that network information is correctly spoofed when
    'privacy.resistFingerprinting' is true. This tests not only windows, but also workers.
    
    MozReview-Commit-ID: Lt6HZlFrcja
    ---
     .../resistfingerprinting/test/browser/browser.ini  |  1 +
     .../test/browser/browser_netInfo.js                | 34 ++++++++++++++++++++++
     dom/network/Connection.cpp                         |  3 +-
     dom/network/Connection.h                           |  8 ++++-
     4 files changed, 44 insertions(+), 2 deletions(-)
     create mode 100644 browser/components/resistfingerprinting/test/browser/browser_netInfo.js
    
    diff --git a/browser/components/resistfingerprinting/test/browser/browser.ini b/browser/components/resistfingerprinting/test/browser/browser.ini
    index 4b81c91d8c6c..b596f437caa2 100644
    a b support-files = 
    44  file_dummy.html
    55  head.js
    66
     7[browser_netInfo.js]
    78[browser_roundedWindow_dialogWindow.js]
    89[browser_roundedWindow_newWindow.js]
    910[browser_roundedWindow_open_max.js]
  • new file rowser/components/resistfingerprinting/test/browser/browser_netInfo.js

    diff --git a/browser/components/resistfingerprinting/test/browser/browser_netInfo.js b/browser/components/resistfingerprinting/test/browser/browser_netInfo.js
    new file mode 100644
    index 000000000000..e1b69dc151a5
    - +  
     1/**
     2 * Bug 1372072 - A test case for check whether network information API has been
     3 *   spoofed correctly when 'privacy.resistFingerprinting' is true;
     4 */
     5
     6const TEST_PATH = "http://example.net/browser/browser/" +
     7                  "components/resistfingerprinting/test/browser/"
     8
     9
     10async function testWindow() {
     11  // Open a tab to test network information in a content.
     12  let tab = await BrowserTestUtils.openNewForegroundTab(
     13    gBrowser, TEST_PATH + "file_dummy.html");
     14
     15  await ContentTask.spawn(tab.linkedBrowser, null, async function() {
     16    ok("connection" in content.navigator, "navigator.connection should exist");
     17
     18    is(content.navigator.connection.type, "unknown", "The connection type is spoofed correctly");
     19  });
     20
     21  await BrowserTestUtils.removeTab(tab);
     22}
     23
     24add_task(async function runTest() {
     25  await SpecialPowers.pushPrefEnv({"set":
     26    [
     27      ["privacy.resistFingerprinting", true],
     28      ["dom.netinfo.enabled",          true]
     29    ]
     30  });
     31
     32  await testWindow();
     33});
     34
  • dom/network/Connection.cpp

    diff --git a/dom/network/Connection.cpp b/dom/network/Connection.cpp
    index 3bf6f40384a6..cc06b5e14b6a 100644
    a b Connection::Notify(const hal::NetworkInformation& aNetworkInfo) 
    7878
    7979  UpdateFromNetworkInfo(aNetworkInfo);
    8080
    81   if (previousType == mType) {
     81  if (previousType == mType ||
     82      nsContentUtils::ShouldResistFingerprinting()) {
    8283    return;
    8384  }
    8485
  • dom/network/Connection.h

    diff --git a/dom/network/Connection.h b/dom/network/Connection.h
    index 907aea144bc0..59759b4b805f 100644
    a b  
    1313#include "mozilla/dom/NetworkInformationBinding.h"
    1414#include "nsCycleCollectionParticipant.h"
    1515#include "nsINetworkProperties.h"
     16#include "nsContentUtils.h"
     17
    1618
    1719namespace mozilla {
    1820
    public: 
    4446
    4547  virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
    4648
    47   ConnectionType Type() const { return mType; }
     49  ConnectionType Type() const
     50  {
     51    return nsContentUtils::ShouldResistFingerprinting() ?
     52             static_cast<ConnectionType>(ConnectionType::Unknown) : mType;
     53  }
    4854
    4955  IMPL_EVENT_HANDLER(typechange)
    5056