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

3rd party fingerprinting protection #75

Merged
merged 3 commits into from
Apr 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ group("child_dependencies") {
group("browser_dependencies") {
public_deps = [
"//brave/browser",
"//brave/components/content_settings/core/browser",
"//brave/extensions",
"common",
":brave_framework_resources",
Expand Down
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ deps = {
"vendor/tracking-protection": "https://github.com/brave/tracking-protection.git@051177425a14121a22087d754ad8eb1c0ce8fb24",
"vendor/hashset-cpp": "https://github.com/brave/hashset-cpp.git@67ffffa69b56e330bab9d08f050727f891c916a1",
"vendor/bloom-filter-cpp": "https://github.com/brave/bloom-filter-cpp.git@d511cf872ea1d650ab8dc4662f6036dac012d197",
"vendor/brave-extension": "https://github.com/brave/brave-extension.git@fd3d4a7b9fc206649d504b8616f095ff9376d03a",
"vendor/brave-extension": "https://github.com/brave/brave-extension.git@6b9e384a74e8be2b1cea8c88e3c25e41e5d8a194",
"vendor/requests": "https://github.com/kennethreitz/requests@e4d59bedfd3c7f4f254f4f5d036587bcd8152458",
"vendor/boto": "https://github.com/boto/boto@f7574aa6cc2c819430c1f05e9a1a1a666ef8169b",
"vendor/python-patch": "https://github.com/svn2github/python-patch@a336a458016ced89aba90dfc3f4c8222ae3b1403",
Expand Down
12 changes: 12 additions & 0 deletions components/content_settings/core/browser/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
source_set("browser") {
sources = [
"brave_host_content_settings_map.cc",
"brave_host_content_settings_map.h",
]

deps = [
]

public_deps = [
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/components/content_settings/core/browser/brave_host_content_settings_map.h"

#include "components/content_settings/core/common/content_settings_pattern.h"

BraveHostContentSettingsMap::BraveHostContentSettingsMap(
PrefService* prefs,
bool is_incognito_profile,
bool is_guest_profile,
bool store_last_modified)
: HostContentSettingsMap(prefs, is_incognito_profile, is_guest_profile,
store_last_modified) {
InitializeFingerprintingContentSetting();
}

BraveHostContentSettingsMap::~BraveHostContentSettingsMap() {
}

void BraveHostContentSettingsMap::InitializeFingerprintingContentSetting() {
SetContentSettingCustomScope(
ContentSettingsPattern::Wildcard(),
ContentSettingsPattern::FromString("https://firstParty/*"),
CONTENT_SETTINGS_TYPE_PLUGINS,
"fingerprinting",
CONTENT_SETTING_ALLOW);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_BRAVE_HOST_CONTENT_SETTINGS_MAP_H_
#define BRAVE_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_BRAVE_HOST_CONTENT_SETTINGS_MAP_H_

#include "components/content_settings/core/browser/host_content_settings_map.h"

class BraveHostContentSettingsMap : public HostContentSettingsMap {
public:
BraveHostContentSettingsMap(PrefService* prefs,
bool is_incognito_profile,
bool is_guest_profile,
bool store_last_modified);
private:
void InitializeFingerprintingContentSetting();
~BraveHostContentSettingsMap() override;
};

#endif // BRAVE_COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_BRAVE_HOST_CONTENT_SETTINGS_MAP_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
diff --git a/chrome/browser/content_settings/host_content_settings_map_factory.cc b/chrome/browser/content_settings/host_content_settings_map_factory.cc
index 7bb265a57ba4c03489743add26adaeea40a9fb06..3f6b1af25a0118ac2b6d388948f0dee49d32f78a 100644
--- a/chrome/browser/content_settings/host_content_settings_map_factory.cc
+++ b/chrome/browser/content_settings/host_content_settings_map_factory.cc
@@ -7,6 +7,7 @@
#include <utility>

#include "base/feature_list.h"
+#include "brave/components/content_settings/core/browser/brave_host_content_settings_map.h"
#include "chrome/browser/profiles/off_the_record_profile_impl.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_features.h"
@@ -81,7 +82,7 @@ scoped_refptr<RefcountedKeyedService>

bool store_last_modified = base::FeatureList::IsEnabled(features::kTabsInCbd);

- scoped_refptr<HostContentSettingsMap> settings_map(new HostContentSettingsMap(
+ scoped_refptr<HostContentSettingsMap> settings_map(new BraveHostContentSettingsMap(
profile->GetPrefs(),
profile->GetProfileType() == Profile::INCOGNITO_PROFILE,
profile->GetProfileType() == Profile::GUEST_PROFILE,
27 changes: 0 additions & 27 deletions patches/chrome-renderer-content_settings_observer.cc.patch

This file was deleted.

15 changes: 1 addition & 14 deletions patches/chrome-renderer-content_settings_observer.h.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/chrome/renderer/content_settings_observer.h b/chrome/renderer/content_settings_observer.h
index 8030dcd98b1fc0e227fe07258c4f7f4ecf7fc46f..6532c1de6fc3fbd0f88d6fdcd4ed3bfcd7528b6d 100644
index 8030dcd98b1fc0e227fe07258c4f7f4ecf7fc46f..249155b16e5faa0ef70d81c08377a4d3e0036fc2 100644
--- a/chrome/renderer/content_settings_observer.h
+++ b/chrome/renderer/content_settings_observer.h
@@ -103,6 +103,7 @@ class ContentSettingsObserver
Expand All @@ -10,16 +10,3 @@ index 8030dcd98b1fc0e227fe07258c4f7f4ecf7fc46f..6532c1de6fc3fbd0f88d6fdcd4ed3bfc
FRIEND_TEST_ALL_PREFIXES(ContentSettingsObserverTest, WhitelistedSchemes);
FRIEND_TEST_ALL_PREFIXES(ContentSettingsObserverBrowserTest,
ContentSettingsInterstitialPages);
@@ -149,6 +150,12 @@ class ContentSettingsObserver
const blink::WebSecurityOrigin& origin,
const blink::WebURL& document_url);

+ template <typename URL>
+ ContentSetting GetContentSettingFromRules(
+ const ContentSettingsForOneType& rules,
+ const blink::WebFrame* frame,
+ const URL& secondary_url);
+
#if BUILDFLAG(ENABLE_EXTENSIONS)
// Owned by ChromeContentRendererClient and outlive us.
extensions::Dispatcher* const extension_dispatcher_;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/components/content_settings/core/browser/host_content_settings_map.h b/components/content_settings/core/browser/host_content_settings_map.h
index 890e8959ae155618b78661dc8e97a81332d654f8..2a1f562e3b37ce85c3de48ea3f753c34c8586bbd 100644
--- a/components/content_settings/core/browser/host_content_settings_map.h
+++ b/components/content_settings/core/browser/host_content_settings_map.h
@@ -303,6 +303,7 @@ class HostContentSettingsMap : public content_settings::Observer,
}

private:
+ friend class BraveHostContentSettingsMap;
friend class base::RefCountedThreadSafe<HostContentSettingsMap>;
friend class content_settings::TestUtils;

40 changes: 40 additions & 0 deletions renderer/brave_content_settings_observer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "base/strings/utf_string_conversions.h"
#include "brave/common/render_messages.h"
#include "components/content_settings/core/common/content_settings_pattern.h"
#include "content/public/renderer/render_frame.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/WebKit/public/platform/WebURL.h"
Expand Down Expand Up @@ -46,6 +47,45 @@ void BraveContentSettingsObserver::DidBlockFingerprinting(
Send(new BraveViewHostMsg_FingerprintingBlocked(routing_id(), details));
}

GURL BraveContentSettingsObserver::GetOriginOrURL(const blink::WebFrame* frame) {
url::Origin top_origin = url::Origin(frame->Top()->GetSecurityOrigin());
// The |top_origin| is unique ("null") e.g., for file:// URLs. Use the
// document URL as the primary URL in those cases.
// TODO(alexmos): This is broken for --site-per-process, since top() can be a
// WebRemoteFrame which does not have a document(), and the WebRemoteFrame's
// URL is not replicated. See https://crbug.com/628759.
if (top_origin.unique() && frame->Top()->IsWebLocalFrame())
return frame->Top()->ToWebLocalFrame()->GetDocument().Url();
return top_origin.GetURL();
}

ContentSetting BraveContentSettingsObserver::GetContentSettingFromRules(
const ContentSettingsForOneType& rules,
const blink::WebLocalFrame* frame,
const GURL& secondary_url) {

const GURL& primary_url = GetOriginOrURL(frame);

for (const auto& rule : rules) {
ContentSettingsPattern secondary_pattern = rule.secondary_pattern;
if (rule.secondary_pattern ==
ContentSettingsPattern::FromString("https://firstParty/*")) {
secondary_pattern = ContentSettingsPattern::FromString(
"[*.]" + GetOriginOrURL(frame).HostNoBrackets());
}

if (rule.primary_pattern.Matches(primary_url) &&
(secondary_pattern == ContentSettingsPattern::Wildcard() ||
secondary_pattern.Matches(secondary_url))) {
return rule.GetContentSetting();
}
}

// for cases which are third party resources and doesn't match any existing
// rules, block them by default
return CONTENT_SETTING_BLOCK;
}

bool BraveContentSettingsObserver::AllowFingerprinting(
bool enabled_per_settings) {
if (!enabled_per_settings)
Expand Down
13 changes: 13 additions & 0 deletions renderer/brave_content_settings_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@

#include "base/strings/string16.h"
#include "chrome/renderer/content_settings_observer.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_types.h"

namespace blink {
class WebLocalFrame;
}

// Handles blocking content per content settings for each RenderFrame.
class BraveContentSettingsObserver
: public ContentSettingsObserver {
Expand All @@ -31,6 +36,14 @@ class BraveContentSettingsObserver
void DidBlockFingerprinting(
const base::string16& details);

private:
GURL GetOriginOrURL(const blink::WebFrame* frame);

ContentSetting GetContentSettingFromRules(
const ContentSettingsForOneType& rules,
const blink::WebLocalFrame* frame,
const GURL& secondary_url);

DISALLOW_COPY_AND_ASSIGN(BraveContentSettingsObserver);
};

Expand Down
Loading