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

strips x-client-data headers from outgoing requests #2549

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions src/_locales/en_US/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@
"message": "Prevent WebRTC from leaking local IP address",
"description": "Checkbox label on the general settings page"
},
"options_x_client_data_setting": {
"message": "Remove Chrome-only identifier from being sent on Google sites",
"description": "Checkbox label on the general settings page for removing the x-client-data header on Chrome"
},
"x_client_data_warning": {
"message": "Chrome HTTP header \"x-client-data\" purportedly used to test new features on Google sites, may cause breakage",
"description": "warning tooltip that appears next to the x-client-data option on the settings page"
},
"intro_welcome": {
"message": "Privacy Badger automatically learns to block invisible trackers. Take a minute to see how.",
"description": "Intro page welcome paragraph."
Expand Down
7 changes: 7 additions & 0 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,7 @@ Badger.prototype = {
learnLocally: false,
migrationLevel: 0,
preventWebRTCIPLeak: false,
removeXClientDataHeader: false,
seenComic: false,
sendDNTSignal: true,
showCounter: true,
Expand Down Expand Up @@ -1125,6 +1126,12 @@ Badger.prototype = {
return this.getSettings().getItem("checkForDNTPolicy");
},

isRemoveXClientDataHeaderEnabled: function() {
if (!chrome.runtime.getBrowserInfo) {
return this.getSettings().getItem("removeXClientDataHeader");
}
},

isFlocOverwriteEnabled: function() {
if (document.interestCohort) {
return this.getSettings().getItem("disableFloc");
Expand Down
16 changes: 16 additions & 0 deletions src/js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,22 @@ function loadOptions() {
});
}

// only show the x-client-data header setting if in Chrome
// TODO: more accurate way to determine this is a Chrome or Chromium browser
Copy link
Member

Choose a reason for hiding this comment

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

X-Client-Data is not in Chromium, only Chrome, I think.

We could try doing feature detection (always better than guessing based on UA). Something like, on Privacy Badger startup, make a dummy request to a Google domain. This request should get cancelled, but before it does, we'll see the headers and set our internal xClientDataHeaderDetected flag.

if (!chrome.runtime.getBrowserInfo) {
$("#remove-x-client-data-toggle").show();
$("#toggle-x-client-data-header-mode")
.prop("checked", OPTIONS_DATA.settings.removeXClientDataHeader)
.on("click", function () {
const removeXClientDataHeader = $("#toggle-x-client-data-header-mode").prop("checked");

chrome.runtime.sendMessage({
type: "updateSettings",
data: { removeXClientDataHeader }
});
});
}

if (OPTIONS_DATA.webRTCAvailable && OPTIONS_DATA.legacyWebRtcProtectionUser) {
$("#webRTCToggle").show();
$("#toggle_webrtc_mode")
Expand Down
14 changes: 9 additions & 5 deletions src/js/webrequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,18 @@ function onBeforeSendHeaders(details) {
type = details.type,
url = details.url;

// option to remove x-client-data headers as well
const removeXClientData = badger.isRemoveXClientDataHeaderEnabled();

if (_isTabChromeInternal(tab_id)) {
// DNT policy requests: strip cookies
if (type == "xmlhttprequest" && url.endsWith("/.well-known/dnt-policy.txt")) {
// remove Cookie headers
let newHeaders = [];

for (let i = 0, count = details.requestHeaders.length; i < count; i++) {
let header = details.requestHeaders[i];
if (header.name.toLowerCase() != "cookie") {
if (header.name.toLowerCase() != "cookie" || (removeXClientData && header.name.toLowerCase() != 'x-client-data')) {
newHeaders.push(header);
}
}
Expand Down Expand Up @@ -256,10 +260,10 @@ function onBeforeSendHeaders(details) {
if (action == constants.COOKIEBLOCK || action == constants.USER_COOKIEBLOCK) {
let newHeaders;

// GET requests: remove cookie headers, reduce referrer header to origin
// GET requests: remove cookie (and x-client-data if option is set) headers, reduce referrer header to origin
if (details.method == "GET") {
newHeaders = details.requestHeaders.filter(header => {
return (header.name.toLowerCase() != "cookie");
return (header.name.toLowerCase() != "cookie" || (removeXClientData && header.name.toLowerCase() != 'x-client-data'));
}).map(header => {
if (header.name.toLowerCase() == "referer") {
header.value = header.value.slice(
Expand All @@ -270,10 +274,10 @@ function onBeforeSendHeaders(details) {
return header;
});

// remove cookie and referrer headers otherwise
// remove cookie, referrer (and x-client-data if option is set) otherwise
} else {
newHeaders = details.requestHeaders.filter(header => {
return (header.name.toLowerCase() != "cookie" && header.name.toLowerCase() != "referer");
return (header.name.toLowerCase() != "cookie" && header.name.toLowerCase() != "referer" && (removeXClientData && header.name.toLowerCase() != 'x-client-data'));
});
}

Expand Down
10 changes: 10 additions & 0 deletions src/skin/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,16 @@ <h4 class="i18n_options_advanced_settings"></h4>
</span>
</label>
</div>
<div class="checkbox" id="remove-x-client-data-toggle" style="display:none">
<label>
<input type="checkbox" id="toggle-x-client-data-header-mode">
<span>
<span class="i18n_options_x_client_data_setting"></span>
<span class="ui-icon ui-icon-alert tooltip" title="i18n_x_client_data_warning"></span>
<a href="https://9to5google.com/2020/02/06/google-chrome-x-client-data-tracking/" target="_blank"><span class="ui-icon ui-icon-circle-b-help"></span></a>
</span>
</label>
</div>

</form>
</div>
Expand Down