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
--- 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)