Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable navigator.keyboard API when fingerprinting protection is on. #10935

Merged
merged 2 commits into from
Nov 16, 2021

Conversation

mkarolin
Copy link
Collaborator

@mkarolin mkarolin commented Nov 8, 2021

Fixes brave/brave-browser#3964

Have not found a convenient way to return navigator.keyboard as
undefined yet, so for now making it a null.

Since this API is not supported by all browsers making an assumption
that web developers would check the API availability before using it
in the form of if (navigator.keyboard)..., in which case a null
should work just as well.

Maybe @pilgrim-brave or @bridiver have a better idea on making it undefined.

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally: npm run test -- brave_browser_tests, npm run test -- brave_unit_tests, npm run lint, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

@mkarolin mkarolin requested a review from a team as a code owner November 8, 2021 17:58
@mkarolin mkarolin self-assigned this Nov 8, 2021
@mkarolin mkarolin requested a review from a team as a code owner November 8, 2021 17:58
@mkarolin mkarolin force-pushed the maxk-disable-navigator-keyboard branch from f4623ae to c56a710 Compare November 10, 2021 18:53
Copy link
Member

@simonhong simonhong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

@pilgrim-brave
Copy link
Contributor

Yeah I don't have any experience conditionally removing an IDL-defined API at runtime. I'm sure it's technically feasible, but this is probably sufficient. If we get webcompat reports, we can revisit.

#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/network_session_configurator/common/network_switches.h"
#include "components/permissions/permission_request.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused? Pls check for unused includes

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 0dfc2a8


using brave_shields::ControlType;

const char kGetLayoutMapScript[] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be constexpr and also raw string literarls are handier

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in 0dfc2a8. Also changed the script itself as it was failing on Windows CI with

15:11:59  ../../brave/browser/farbling/brave_navigator_keyboard_api_browsertest.cc(116): error: Expected equality of these values:
15:11:59  
15:11:59    "a"
15:11:59  
15:11:59      Which is: 00007FF7741DC7BD
15:11:59  
15:11:59    EvalJs(contents(), kGetLayoutMapScript)
15:11:59  
15:11:59      Which is: null

Assuming, because there's no physical keyboard?

void SetUpCommandLine(base::CommandLine* command_line) override {
// HTTPS server only serves a valid cert for localhost, so this is needed
// to load pages from other hosts without an error
command_line->AppendSwitch(switches::kIgnoreCertificateErrors);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better avoid this (as per annoucement on slack)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0dfc2a8

Fixes brave/brave-browser#3964

Have not found a convenient way to return navigator.keyboard as
undefined yet, so for now making it a null.

Since this API is not supported by all browsers making an assumption
that web developers would check the API availability before using it
in the form of `if (navigator.keyboard)...`, in which case a null
should work just as well.
@mkarolin mkarolin force-pushed the maxk-disable-navigator-keyboard branch from c56a710 to 0dfc2a8 Compare November 15, 2021 16:51
Copy link
Member

@goodov goodov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ with few nits

#include "chrome/common/chrome_content_client.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/network_session_configurator/common/network_switches.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used anymore

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh! Removed in 2653b6b


using brave_shields::ControlType;

constexpr char kGetLayoutMapScript[] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

namespace {

}  // namespace

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 2653b6b

@mkarolin mkarolin force-pushed the maxk-disable-navigator-keyboard branch from 0dfc2a8 to 2653b6b Compare November 16, 2021 14:15
@mkarolin mkarolin merged commit 116fc0d into master Nov 16, 2021
@mkarolin mkarolin deleted the maxk-disable-navigator-keyboard branch November 16, 2021 16:52
@mkarolin mkarolin added this to the 1.34.x - Nightly milestone Nov 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disable Keyboard API fingerprinting
5 participants