Skip to content

Commit c745791

Browse files
don't perturb pixels on google maps (#23416)
This is a temporary fix for Google Maps; we will revert it once a better fix is found.
1 parent 746c975 commit c745791

File tree

2 files changed

+81
-6
lines changed

2 files changed

+81
-6
lines changed

chromium_src/third_party/blink/renderer/modules/canvas/canvas2d/base_rendering_context_2d.cc

+23-6
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,30 @@
88
#include "base/notreached.h"
99
#include "brave/third_party/blink/renderer/core/farbling/brave_session_cache.h"
1010
#include "third_party/blink/renderer/platform/graphics/image_data_buffer.h"
11+
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
1112

12-
#define BRAVE_GET_IMAGE_DATA \
13-
if (ExecutionContext* context = ExecutionContext::From(script_state)) { \
14-
SkPixmap image_data_pixmap = image_data->GetSkPixmap(); \
15-
brave::BraveSessionCache::From(*context).PerturbPixels( \
16-
static_cast<const unsigned char*>(image_data_pixmap.writable_addr()), \
17-
image_data_pixmap.computeByteSize()); \
13+
namespace {
14+
15+
bool IsGoogleMaps(const blink::KURL& url) {
16+
const auto host = url.Host();
17+
if (!host.StartsWith("google.") && !host.Contains(".google.")) {
18+
return false;
19+
}
20+
const auto path = url.GetPath();
21+
return path.StartsWith("/maps/") || path == "/maps";
22+
}
23+
24+
} // namespace
25+
26+
#define BRAVE_GET_IMAGE_DATA \
27+
if (ExecutionContext* context = ExecutionContext::From(script_state)) { \
28+
if (!IsGoogleMaps(context->Url())) { \
29+
SkPixmap image_data_pixmap = image_data->GetSkPixmap(); \
30+
brave::BraveSessionCache::From(*context).PerturbPixels( \
31+
static_cast<const unsigned char*>( \
32+
image_data_pixmap.writable_addr()), \
33+
image_data_pixmap.computeByteSize()); \
34+
} \
1835
}
1936

2037
#define BRAVE_BASE_RENDERING_CONTEXT_2D_MEASURE_TEXT \

components/content_settings/renderer/brave_content_settings_agent_impl_browsertest.cc

+58
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "components/content_settings/core/browser/host_content_settings_map.h"
2222
#include "components/content_settings/core/common/content_settings.h"
2323
#include "components/content_settings/core/common/content_settings_types.h"
24+
#include "components/google/core/common/google_switches.h"
2425
#include "components/network_session_configurator/common/network_switches.h"
2526
#include "content/public/browser/render_frame_host.h"
2627
#include "content/public/test/browser_test.h"
@@ -31,10 +32,13 @@
3132
#include "net/http/http_request_headers.h"
3233
#include "net/test/embedded_test_server/default_handlers.h"
3334
#include "net/test/embedded_test_server/http_request.h"
35+
#include "net/test/embedded_test_server/request_handler_util.h"
3436
#include "testing/gmock/include/gmock/gmock.h"
3537
#include "url/origin.h"
3638

3739
using brave_shields::ControlType;
40+
using net::test_server::HttpRequest;
41+
using net::test_server::HttpResponse;
3842

3943
namespace {
4044

@@ -74,6 +78,7 @@ const int kExpectedImageDataHashFarblingBalanced = 172;
7478
const int kExpectedImageDataHashFarblingOff = 0;
7579
const int kExpectedImageDataHashFarblingMaximum =
7680
kExpectedImageDataHashFarblingBalanced;
81+
const int kExpectedImageDataHashFarblingBalancedGoogleCom = 182;
7782

7883
const char kEmptyCookie[] = "";
7984

@@ -97,6 +102,19 @@ GURL GetOriginURL(const GURL& url) {
97102
return url::Origin::Create(url).GetURL();
98103
}
99104

105+
// Remaps requests from /maps/simple.html to /simple.html
106+
std::unique_ptr<HttpResponse> HandleGoogleMapsFileRequest(
107+
const base::FilePath& server_root,
108+
const HttpRequest& request) {
109+
HttpRequest new_request(request);
110+
if (!new_request.relative_url.starts_with("/maps")) {
111+
// This handler is only relevant for a Google Maps url.
112+
return nullptr;
113+
}
114+
new_request.relative_url = new_request.relative_url.substr(5);
115+
return HandleFileRequest(server_root, new_request);
116+
}
117+
100118
} // namespace
101119

102120
class BraveContentSettingsAgentImplBrowserTest : public InProcessBrowserTest {
@@ -117,6 +135,8 @@ class BraveContentSettingsAgentImplBrowserTest : public InProcessBrowserTest {
117135
https_server_.SetSSLConfig(net::EmbeddedTestServer::CERT_TEST_NAMES);
118136
https_server_.ServeFilesFromDirectory(test_data_dir);
119137
https_server_.AddDefaultHandlers(GetChromeTestDataDir());
138+
https_server_.RegisterDefaultHandler(
139+
base::BindRepeating(&HandleGoogleMapsFileRequest, test_data_dir));
120140
content::SetupCrossSiteRedirector(&https_server_);
121141
https_server_.RegisterRequestMonitor(base::BindRepeating(
122142
&BraveContentSettingsAgentImplBrowserTest::SaveReferrer,
@@ -143,6 +163,16 @@ class BraveContentSettingsAgentImplBrowserTest : public InProcessBrowserTest {
143163
ContentSettingsPattern::FromString("https://firstParty/*");
144164
}
145165

166+
void SetUpCommandLine(base::CommandLine* command_line) override {
167+
// Since the HTTPS server only serves a valid cert for localhost,
168+
// this is needed to load pages from "www.google.*" without an interstitial.
169+
command_line->AppendSwitch(switches::kIgnoreCertificateErrors);
170+
171+
// The production code only allows known ports (80 for http and 443 for
172+
// https), but the test server runs on a random port.
173+
command_line->AppendSwitch(switches::kIgnoreGooglePortNumbers);
174+
}
175+
146176
void SaveReferrer(const net::test_server::HttpRequest& request) {
147177
base::AutoLock auto_lock(last_referrers_lock_);
148178

@@ -430,6 +460,34 @@ IN_PROC_BROWSER_TEST_F(BraveContentSettingsAgentImplBrowserTest,
430460
content::EvalJs(contents(), kGetImageDataScript));
431461
}
432462

463+
IN_PROC_BROWSER_TEST_F(BraveContentSettingsAgentImplBrowserTest,
464+
FarbleGetImageDataGoogleMapsException) {
465+
// Farbling should be disabled on Google Maps
466+
SetFingerprintingDefault();
467+
ASSERT_TRUE(ui_test_utils::NavigateToURL(
468+
browser(), https_server().GetURL("google.com", "/maps/simple.html")));
469+
EXPECT_EQ(kExpectedImageDataHashFarblingOff,
470+
content::EvalJs(contents(), kGetImageDataScript));
471+
472+
// Farbling should not be disabled on other Google things
473+
ASSERT_TRUE(ui_test_utils::NavigateToURL(
474+
browser(), https_server().GetURL("google.com", "/simple.html")));
475+
EXPECT_EQ(kExpectedImageDataHashFarblingBalancedGoogleCom,
476+
content::EvalJs(contents(), kGetImageDataScript));
477+
478+
// Farbling should be disabled on google.co.uk maps
479+
ASSERT_TRUE(ui_test_utils::NavigateToURL(
480+
browser(), https_server().GetURL("google.co.uk", "/maps/simple.html")));
481+
EXPECT_EQ(kExpectedImageDataHashFarblingOff,
482+
content::EvalJs(contents(), kGetImageDataScript));
483+
484+
// Farbling should be disabled on google.de maps
485+
ASSERT_TRUE(ui_test_utils::NavigateToURL(
486+
browser(), https_server().GetURL("google.de", "/maps/simple.html")));
487+
EXPECT_EQ(kExpectedImageDataHashFarblingOff,
488+
content::EvalJs(contents(), kGetImageDataScript));
489+
}
490+
433491
class BraveContentSettingsAgentImplV2BrowserTest
434492
: public BraveContentSettingsAgentImplBrowserTest {
435493
public:

0 commit comments

Comments
 (0)