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

Always return light mode in fingerprinting strict mode #8832

Merged
merged 1 commit into from
Jun 1, 2021

Conversation

ShivanKaul
Copy link
Collaborator

@ShivanKaul ShivanKaul commented May 17, 2021

This PR adds a patch to `blink/renderer/core/css/media_values.cc` that always returns `mojom::PreferredColorScheme::kLight` if fingerprinting mode is strict. Note that a page's override media feature will still be respected.

On @bridiver's recommendation, overriding BraveContentBrowserClient::OverrideWebPreferencesAfterNavigation to return light mode if fingerprinting mode = strict instead of patching blink/renderer/core/css/media_values.cc.
Resolves brave/brave-browser#15265.

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:

@ShivanKaul ShivanKaul requested a review from pes10k May 17, 2021 20:40
@ShivanKaul ShivanKaul requested a review from a team as a code owner May 17, 2021 20:40
@pes10k
Copy link
Contributor

pes10k commented May 17, 2021

This looks great, though a few Qs:

  1. Is there any issue related to workers here? Is this approach able to find the right origin in a worker process?
  2. I think AllowFingerprinting will return false with default fingerprinting protections. If thats correct, the intended behavior here is to only apply this protection in "strict" mode

cc @pilgrim-brave who's expertise here would be appreciated :)

@ShivanKaul ShivanKaul force-pushed the fingerprinting/dark-mode-block branch 2 times, most recently from 7e359a3 to ce8cb65 Compare May 17, 2021 23:28
@pilgrim-brave
Copy link
Contributor

  1. I think AllowFingerprinting will return false with default fingerprinting protections. If thats correct, the intended behavior here is to only apply this protection in "strict" mode

Incorrect. For historical reasons, AllowFingerprinting returns true on default settings. Shivan's code is correct.

@pilgrim-brave
Copy link
Contributor

  1. Is there any issue related to workers here? Is this approach able to find the right origin in a worker process?

No issues with workers for CSS things.

@pilgrim-brave
Copy link
Contributor

Please update the description of this PR to note that we will still respect a page's media feature override. It's just the user's preferred color scheme that is being overridden.

@pilgrim-brave
Copy link
Contributor

Also, tests.

@ShivanKaul
Copy link
Collaborator Author

ShivanKaul commented May 19, 2021

Writing the test was a lot trickier than the actual feature 😅 (thanks a lot Mark for the help with figuring out what test dependency to add) and had to run sync again. I took inspiration from the Chromium test. I've updated the PR.

Copy link
Contributor

@pes10k pes10k left a comment

Choose a reason for hiding this comment

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

Looks good to me (and thanks to @pilgrim-brave for ducking in too)

Are the CI failures unrelated?

@ShivanKaul
Copy link
Collaborator Author

ShivanKaul commented May 21, 2021

Are the CI failures unrelated?

I think so, but digging in - these are the failing tests on Linux:

linux / test-browser / RewardsBrowserTest.ShowACPercentInThePanel | 5.5 sec | 1
linux / test-browser / RewardsNotificationBrowserTest.InsufficientNotificationForACNotEnoughFunds | 5.5 sec | 1
linux / test-browser / BraveAdsBrowserTest/BraveAdsUpgradeBrowserTest.UpgradePath/PreferencesForVersion070WithRewardsAndAdsEnabled_ForSupportedLocale_ForUnsupportedLocale_RewardsShouldBeEnabled_AdsShouldBeEnabled | 0.45 sec | 2
linux / test-browser / BraveAdsBrowserTest/BraveAdsUpgradeBrowserTest.UpgradePath/PreferencesForVersion072WithRewardsAndAdsEnabled_ForSupportedLocale_ForUnsupportedLocale_RewardsShouldBeEnabled_AdsShouldBeEnabled

and on Mac:

macos-x64 / test-browser / AdBlockServiceTest.CnameCloakedRequestsGetBlocked

The latter looks like will be solved by #8883

@pilgrim-brave
Copy link
Contributor

Are the CI failures unrelated?

I think so, but digging in - these are the failing tests on Linux:

Those are unrelated.

@ShivanKaul ShivanKaul force-pushed the fingerprinting/dark-mode-block branch from f66f5bf to fe6c1fc Compare May 21, 2021 17:05
if (value.IsValid())
return CSSValueIDToPreferredColorScheme(value.id);
}
+ BRAVE_DARK_MODE_DETECTION_DISABLED
Copy link
Collaborator

Choose a reason for hiding this comment

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

this does not require patching, it can be controlled in the browser process in ContentBrowserClient::OverrideWebPreferencesAfterNavigation

Copy link
Collaborator

@bridiver bridiver left a comment

Choose a reason for hiding this comment

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

preferred color can be changed using web prefs


bool NavigateToURLUntilLoadStop(const GURL& url) {
ui_test_utils::NavigateToURL(browser(), url);
return WaitForLoadStop(contents());
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should ASSERT_TRUE and vs return since you're not doing anything with the return value anyway

@ShivanKaul ShivanKaul force-pushed the fingerprinting/dark-mode-block branch from af01a80 to 0668563 Compare May 25, 2021 19:31
void SetUpOnMainThread() override {
InProcessBrowserTest::SetUpOnMainThread();

content_client_.reset(new ChromeContentClient);
Copy link
Collaborator

Choose a reason for hiding this comment

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

this doesn't seem necessary for anything

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed, I went and removed a bunch of other unnecessary stuff in the test and tried to prune the includes as much as possible.

};

IN_PROC_BROWSER_TEST_F(BraveDarkModeFingerprintProtection, DarkModeCheck) {
test_theme_.SetDarkMode(true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

you should also test with SetDarkMode(false) to ensure that it isn't affected by this change

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done!

@ShivanKaul ShivanKaul force-pushed the fingerprinting/dark-mode-block branch 2 times, most recently from f134807 to daf0eb3 Compare May 26, 2021 01:00
@ShivanKaul ShivanKaul force-pushed the fingerprinting/dark-mode-block branch from daf0eb3 to 15ce4a5 Compare May 28, 2021 16:11
@ShivanKaul
Copy link
Collaborator Author

The CI is failing on the Android build which seems to be failing since yesterday. @mihaiplesa helped me dig up the failures on Android and they don't seem to be connected to my changes (which should have nothing to do with Android).

[2021-05-28T16:48:39.057Z] FAILED: obj/chrome/android/chrome_app_java_resources.resources.zip obj/chrome/android/chrome_app_java_resources.resources.zip.info gen/chrome/android/chrome_app_java_resources_R.txt 
[2021-05-28T16:48:39.057Z] python ../../build/android/gyp/prepare_resources.py --depfile gen/chrome/android/chrome_app_java_resources.d --res-sources-path=gen/chrome/android/chrome_app_java_resources.res.sources --resource-zip-out obj/chrome/android/chrome_app_java_resources.resources.zip --r-text-out gen/chrome/android/chrome_app_java_resources_R.txt
[2021-05-28T16:48:39.058Z] Error: Found files not listed in the sources list of the BUILD.gn target:
[2021-05-28T16:48:39.058Z] ../../chrome/android/java/res/xml/background_video_playback_preference.xml
[2021-05-28T16:48:39.058Z] ../../chrome/android/java/res/xml/closing_all_tabs_closes_brave_preference.xml
[2021-05-28T16:48:39.058Z] [35438/52923] ACTION //chrome/browser/search_engines/android:java__process__bytecode_rewrite(//build/toolchain/android:android_clang_x86)
[2021-05-28T16:48:39.058Z] change superclass of org/chromium/chrome/browser/search_engines/settings/SearchEngineAdapter to org/chromium/chrome/browser/search_engines/settings/BraveBaseSearchEngineAdapter
[2021-05-28T16:48:39.058Z] make mSearchEngineAdapter public in org/chromium/chrome/browser/search_engines/settings/SearchEngineSettings
[2021-05-28T16:48:39.058Z] use invoke virtual for call to method org/chromium/chrome/browser/search_engines/settings/SearchEngineSettings.createAdapterIfNecessary
[2021-05-28T16:48:39.058Z] use invoke virtual for call to method org/chromium/chrome/browser/search_engines/settings/SearchEngineSettings.createAdapterIfNecessary
[2021-05-28T16:48:39.058Z] use invoke virtual for call to method org/chromium/chrome/browser/search_engines/settings/SearchEngineSettings.createAdapterIfNecessary
[2021-05-28T16:48:39.058Z] make createAdapterIfNecessary public in org/chromium/chrome/browser/search_engines/settings/SearchEngineSettings
[2021-05-28T16:48:39.058Z] redirecting ownership for android/widget/BaseAdapter.<init> in org/chromium/chrome/browser/search_engines/settings/SearchEngineAdapter - new owner org/chromium/chrome/browser/search_engines/settings/BraveBaseSearchEngineAdapter

- Override web preference setting in browser process instead of patch
- Add tests for dark mode fingerprinting protection
- Add deps in brave/browser/farbling
@ShivanKaul ShivanKaul force-pushed the fingerprinting/dark-mode-block branch from 15ce4a5 to 98a2af4 Compare June 1, 2021 12:54
@ShivanKaul
Copy link
Collaborator Author

After rebasing a couple of times, there's only one test crashing on Linux CI: RewardsContributionBrowserTest.AutoContributionMultiplePublishersUphold. This just started failing at brave/components/brave_rewards/browser/test/common/rewards_browsertest_context_util.cc:128 because of Internal Error: ExecuteScriptHelper failed and looks disconnected from my changes, so I'll go ahead and merge my changes in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fingerprinting v3: Dark Mode detection
4 participants