Bug 1222285 - Part 2: Making the keyboard events of modifier keys been suppressed when 'privacy.resistFingerprinting' is true. r?masayuki,arthuredelstein draft
authorTim Huang <tihuang@mozilla.com>
Thu, 31 Aug 2017 11:14:14 +0800
changeset 720799 d74e47db32dbb2bfb0e22728ad788494b72d343e
parent 720798 bec2a7fde9ea2508dd874106cb494453d06fbd50
child 720800 d96b6076b877b9221eb3a94686a7b726a07bf184
child 720905 16af7d72a287176cb3d0fb1d8e46fb7dc48f9fc4
child 721356 19c52a71772b50806533d022f1b107f96f61cdc9
push id95644
push userbmo:tihuang@mozilla.com
push dateTue, 16 Jan 2018 09:13:15 +0000
reviewersmasayuki, arthuredelstein
bugs1222285
milestone59.0a1
Bug 1222285 - Part 2: Making the keyboard events of modifier keys been suppressed when 'privacy.resistFingerprinting' is true. r?masayuki,arthuredelstein This patch makes 'Shift', 'Alt', 'Contorl' and 'AltGraph' been suppressed for content when fingerprinting resistance is enabled. Chrome can still get these events. The reason behind this is that websites can still observe key combinations to tell which keyboard layout is using even we spoof the keyboardEvent.code, keyboardEvent.keyCode and modifier states. For example, the AZERTY France keyboard, the digit keys of it requires the user press the Shift key. So, it is easy to differentiate AZERTY and QWERTY keyboard by observing whether a Shift key generates its own before the digit keys. There are similar issues for 'Alt' and 'AltGraph' as well. MozReview-Commit-ID: 3CwCgvey4lK
layout/base/PresShell.cpp
widget/BasicEvents.h
widget/WidgetEventImpl.cpp
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -7975,16 +7975,20 @@ PresShell::DispatchEventToDOM(WidgetEven
     } else if (mDocument) {
       eventTarget = do_QueryInterface(mDocument);
       // If we don't have any content, the callback wouldn't probably
       // do nothing.
       eventCBPtr = nullptr;
     }
   }
   if (eventTarget) {
+    if (aEvent->IsBlockedForFingerprintingResistance()) {
+      aEvent->mFlags.mOnlySystemGroupDispatchInContent = true;
+    }
+
     if (aEvent->mClass == eCompositionEventClass) {
       IMEStateManager::DispatchCompositionEvent(eventTarget, mPresContext,
                                                 aEvent->AsCompositionEvent(),
                                                 aStatus, eventCBPtr);
     } else {
       EventDispatcher::Dispatch(eventTarget, mPresContext,
                                 aEvent, nullptr, aStatus, eventCBPtr);
     }
--- a/widget/BasicEvents.h
+++ b/widget/BasicEvents.h
@@ -857,16 +857,20 @@ public:
    * Whether the event should cause a DOM event.
    */
   bool IsAllowedToDispatchDOMEvent() const;
   /**
    * Whether the event should be dispatched in system group.
    */
   bool IsAllowedToDispatchInSystemGroup() const;
   /**
+   * Whether the event should be blocked for fingerprinting resistance.
+   */
+  bool IsBlockedForFingerprintingResistance() const;
+  /**
    * Initialize mComposed
    */
   void SetDefaultComposed()
   {
     switch (mClass) {
       case eCompositionEventClass:
         mFlags.mComposed = mMessage == eCompositionStart ||
                            mMessage == eCompositionUpdate ||
--- a/widget/WidgetEventImpl.cpp
+++ b/widget/WidgetEventImpl.cpp
@@ -505,16 +505,34 @@ bool
 WidgetEvent::IsAllowedToDispatchInSystemGroup() const
 {
   // We don't expect to implement default behaviors with pointer events because
   // if we do, prevent default on mouse events can't prevent default behaviors
   // anymore.
   return mClass != ePointerEventClass;
 }
 
+bool
+WidgetEvent::IsBlockedForFingerprintingResistance() const
+{
+  if (mClass == eKeyboardEventClass &&
+      nsContentUtils::ShouldResistFingerprinting()) {
+    const WidgetKeyboardEvent* keyboardEvent = AsKeyboardEvent();
+
+    if (keyboardEvent->mKeyNameIndex == KEY_NAME_INDEX_Alt     ||
+        keyboardEvent->mKeyNameIndex == KEY_NAME_INDEX_Shift   ||
+        keyboardEvent->mKeyNameIndex == KEY_NAME_INDEX_Control ||
+        keyboardEvent->mKeyNameIndex == KEY_NAME_INDEX_AltGraph) {
+      return true;
+    }
+  }
+
+  return false;
+}
+
 /******************************************************************************
  * mozilla::WidgetEvent
  *
  * Misc methods.
  ******************************************************************************/
 
 static dom::EventTarget*
 GetTargetForDOMEvent(nsIDOMEventTarget* aTarget)