-
Notifications
You must be signed in to change notification settings - Fork 920
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement navigator.userAgent farbling in workers
- Loading branch information
1 parent
4fa4b5d
commit 3ceacd7
Showing
7 changed files
with
99 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
chromium_src/third_party/blink/renderer/core/workers/worker_navigator.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
* 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 <random> | ||
|
||
#include "third_party/blink/public/platform/web_content_settings_client.h" | ||
#include "third_party/blink/renderer/core/execution_context/execution_context.h" | ||
|
||
#define BRAVE_WORKERNAVIGATOR_USERAGENT \ | ||
if (blink::WebContentSettingsClient* settings = \ | ||
brave::GetContentSettingsClientFor(GetExecutionContext())) { \ | ||
if (!settings->AllowFingerprinting(true)) { \ | ||
return brave::BraveSessionCache::From(*(GetExecutionContext())) \ | ||
.FarbledUserAgent(user_agent_); \ | ||
} \ | ||
} | ||
|
||
#include "../../../../../../../third_party/blink/renderer/core/workers/worker_navigator.cc" | ||
|
||
#undef BRAVE_WORKERNAVIGATOR_USERAGENT |
12 changes: 12 additions & 0 deletions
12
patches/third_party-blink-renderer-core-workers-worker_navigator.cc.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
diff --git a/third_party/blink/renderer/core/workers/worker_navigator.cc b/third_party/blink/renderer/core/workers/worker_navigator.cc | ||
index 2be0731c9f863f095f89f5d8f1888f4ee3c4cdff..5e60369a236757def5b6c5109983b7a9240fcdc9 100644 | ||
--- a/third_party/blink/renderer/core/workers/worker_navigator.cc | ||
+++ b/third_party/blink/renderer/core/workers/worker_navigator.cc | ||
@@ -47,6 +47,7 @@ WorkerNavigator::WorkerNavigator(const String& user_agent, | ||
WorkerNavigator::~WorkerNavigator() = default; | ||
|
||
String WorkerNavigator::userAgent() const { | ||
+ BRAVE_WORKERNAVIGATOR_USERAGENT | ||
return user_agent_; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!DOCTYPE html> | ||
<!-- navigator.userAgent test from workers --> | ||
<html> | ||
<head> | ||
<title></title> | ||
<meta charset="utf-8"> | ||
</head> | ||
<body> | ||
<script> | ||
var worker = function() { | ||
postMessage(navigator.userAgent); | ||
} | ||
|
||
var workerBlob = new Blob(['(' + worker.toString() + ')()'], { | ||
type: "text/javascript" | ||
}); | ||
|
||
worker = new Worker(window.URL.createObjectURL(workerBlob)); | ||
worker.onmessage = function (e) { | ||
if (navigator.userAgent == e.data) { | ||
document.title = "pass"; | ||
} else { | ||
document.title = "fail"; | ||
} | ||
}; | ||
</script> | ||
</body> | ||
</html> |