Bug 1433592 - Don't spoof ctrl key modifier for privacy.resistFingerprinting=true r=masayuki
☠☠ backed out by ed46fff108c1 ☠ ☠
authorArthur Edelstein <arthuredelstein@gmail.com>
Thu, 01 Mar 2018 16:25:00 +0200
changeset 461303 f15ab7984211cc4252982b3e61bc75543e70a9a3
parent 461302 a2507d4da91b3539dbd80b2d9e6c33d82c861cbc
child 461304 1a74aee7c5498625d7f6ddc9676bf931a225503b
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1433592
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1433592 - Don't spoof ctrl key modifier for privacy.resistFingerprinting=true r=masayuki
browser/components/resistfingerprinting/test/browser/browser_spoofing_keyboard_event.js
dom/events/KeyboardEvent.cpp
toolkit/components/resistfingerprinting/nsRFPService.cpp
--- a/browser/components/resistfingerprinting/test/browser/browser_spoofing_keyboard_event.js
+++ b/browser/components/resistfingerprinting/test/browser/browser_spoofing_keyboard_event.js
@@ -616,16 +616,26 @@ const TEST_CASES_EN = [
               location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, altKey: false, shiftKey: false,
               ctrlKey: false, altGraphKey: false }
   },
   { key: "KEY_F12", modifiers: {}, expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_NON_PRINTABLE,
     result: { key: "F12", code: "F12", charCode: 123, keyCode: KeyboardEvent.DOM_VK_F12,
               location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, altKey: false, shiftKey: false,
               ctrlKey: false, altGraphKey: false }
   },
+  { key: "a", modifiers: { ctrlKey: true }, expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE,
+    result: { key: "a", code: "KeyA", charCode: 97, keyCode: KeyboardEvent.DOM_VK_A,
+              location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, altKey: false, shiftKey: false,
+              ctrlKey: true, altGraphKey: false }
+  },
+  { key: "a", modifiers: { altKey: true }, expectedKeyEvent: SHOULD_DELIVER_ALL_FOR_PRINTABLE,
+    result: { key: "a", code: "KeyA", charCode: 97, keyCode: KeyboardEvent.DOM_VK_A,
+              location: KeyboardEvent.DOM_KEY_LOCATION_STANDARD, altKey: false, shiftKey: false,
+              ctrlKey: false, altGraphKey: false }
+  },
 ];
 
 async function testKeyEvent(aTab, aTestCase) {
   // Prepare all expected key events.
   let testEvents = [];
 
   if (aTestCase.expectedKeyEvent & SHOULD_DELIVER_KEYDOWN) {
     testEvents.push("keydown");
--- a/dom/events/KeyboardEvent.cpp
+++ b/dom/events/KeyboardEvent.cpp
@@ -44,25 +44,20 @@ KeyboardEvent::AltKey(CallerType aCaller
   // modifier key in certain keyboard layout. For example, the '@' key for
   // German keyboard for MAC is Alt+L.
   return GetSpoofedModifierStates(Modifier::MODIFIER_ALT, altState);
 }
 
 bool
 KeyboardEvent::CtrlKey(CallerType aCallerType)
 {
-  bool ctrlState = mEvent->AsKeyboardEvent()->IsControl();
-
-  if (!ShouldResistFingerprinting(aCallerType)) {
-    return ctrlState;
-  }
-
-  // We need to give a spoofed state for Control key since it could be used as a
-  // modifier key in certain asian keyboard layouts.
-  return GetSpoofedModifierStates(Modifier::MODIFIER_CONTROL, ctrlState);
+  // We don't spoof this key when privacy.resistFingerprinting
+  // is enabled, because it is often used for command key
+  // combinations in web apps.
+  return mEvent->AsKeyboardEvent()->IsControl();
 }
 
 bool
 KeyboardEvent::ShiftKey(CallerType aCallerType)
 {
   bool shiftState = mEvent->AsKeyboardEvent()->IsShift();
 
   if (!ShouldResistFingerprinting(aCallerType)) {
@@ -70,16 +65,19 @@ KeyboardEvent::ShiftKey(CallerType aCall
   }
 
   return GetSpoofedModifierStates(Modifier::MODIFIER_SHIFT, shiftState);
 }
 
 bool
 KeyboardEvent::MetaKey()
 {
+  // We don't spoof this key when privacy.resistFingerprinting
+  // is enabled, because it is often used for command key
+  // combinations in web apps.
   return mEvent->AsKeyboardEvent()->IsMeta();
 }
 
 bool
 KeyboardEvent::Repeat()
 {
   return mEvent->AsKeyboardEvent()->mIsRepeat;
 }
--- a/toolkit/components/resistfingerprinting/nsRFPService.cpp
+++ b/toolkit/components/resistfingerprinting/nsRFPService.cpp
@@ -622,18 +622,20 @@ nsRFPService::GetSpoofedModifierStates(c
 {
   MOZ_ASSERT(aKeyboardEvent);
 
   // For modifier or control keys, we don't need to hide its modifier states.
   if (aKeyboardEvent->mKeyNameIndex != KEY_NAME_INDEX_USE_STRING) {
     return false;
   }
 
-  // We will spoof the modifer state for Alt, Shift, AltGraph and Control.
-  if (aModifier & (MODIFIER_ALT | MODIFIER_SHIFT | MODIFIER_ALTGRAPH | MODIFIER_CONTROL)) {
+  // We will spoof the modifer state for Alt, Shift, and AltGraph.
+  // We don't spoof the Control key, because it is often used
+  // for command key combinations in web apps.
+  if (aModifier & (MODIFIER_ALT | MODIFIER_SHIFT | MODIFIER_ALTGRAPH)) {
     SpoofingKeyboardCode keyCodeInfo;
 
     if (GetSpoofedKeyCodeInfo(aDoc, aKeyboardEvent, keyCodeInfo)) {
       aOut = keyCodeInfo.mModifierStates & aModifier;
       return true;
     }
   }