Bug 583181 - Part 3: Spoof navigator.buildID for web content. r=hsivonen

But still allow chrome scripts and (unless resisting fingerprinting) "https://*.mozilla.org" pages to access the real navigator.buildID.

Differential Revision: https://phabricator.services.mozilla.com/D7262

--HG--
extra : rebase_source : ca7e31ae680ec8a9f2af44e2903ee511ff833aa1
extra : source : 02825955013c402b1ef94cf0c7c29637ae5bdd77
This commit is contained in:
Chris Peterson 2018-09-23 17:32:46 -07:00
parent e70234b350
commit 01bd29ee40
4 changed files with 25 additions and 6 deletions

View File

@ -43,7 +43,6 @@ const SPOOFED_UA_OS = {
android: "Android 6.0; Mobile",
other: "X11; Linux x86_64",
};
const SPOOFED_BUILDID = "20100101";
const SPOOFED_HW_CONCURRENCY = 2;
const CONST_APPCODENAME = "Mozilla";
@ -70,7 +69,6 @@ async function testNavigator() {
is(result.mimeTypesLength, 0, "Navigator.mimeTypes has a length of 0.");
is(result.pluginsLength, 0, "Navigator.plugins has a length of 0.");
is(result.oscpu, SPOOFED_OSCPU[AppConstants.platform], "Navigator.oscpu is correctly spoofed.");
is(result.buildID, SPOOFED_BUILDID, "Navigator.buildID is correctly spoofed.");
is(result.hardwareConcurrency, SPOOFED_HW_CONCURRENCY, "Navigator.hardwareConcurrency is correctly spoofed.");
is(result.appCodeName, CONST_APPCODENAME, "Navigator.appCodeName reports correct constant value.");
@ -140,7 +138,6 @@ add_task(async function runOverrideTest() {
["general.platform.override", "platform overridden"],
["general.useragent.override", "userAgent overridden"],
["general.oscpu.override", "oscpu overridden"],
["general.buildID.override", "buildID overridden"],
],
});

View File

@ -20,7 +20,6 @@
result.mimeTypesLength = navigator.mimeTypes.length;
result.pluginsLength = navigator.plugins.length;
result.oscpu = navigator.oscpu;
result.buildID = navigator.buildID;
result.hardwareConcurrency = navigator.hardwareConcurrency;
// eslint-disable-next-line no-unsanitized/property

View File

@ -573,12 +573,35 @@ Navigator::GetBuildID(nsAString& aBuildID, CallerType aCallerType,
aBuildID.AssignLiteral(LEGACY_BUILD_ID);
return;
}
nsAutoString override;
nsresult rv = Preferences::GetString("general.buildID.override", override);
if (NS_SUCCEEDED(rv)) {
aBuildID = override;
return;
}
nsAutoCString host;
bool isHTTPS = false;
if (mWindow) {
nsCOMPtr<nsIDocument> doc = mWindow->GetDoc();
if (doc) {
nsIURI* uri = doc->GetDocumentURI();
if (uri) {
MOZ_ALWAYS_SUCCEEDS(uri->SchemeIs("https", &isHTTPS));
if (isHTTPS) {
MOZ_ALWAYS_SUCCEEDS(uri->GetHost(host));
}
}
}
}
// Spoof the buildID on pages not loaded from "https://*.mozilla.org".
if (!isHTTPS ||
!StringEndsWith(host, NS_LITERAL_CSTRING(".mozilla.org"))) {
aBuildID.AssignLiteral(LEGACY_BUILD_ID);
return;
}
}
nsCOMPtr<nsIXULAppInfo> appInfo =

View File

@ -33,8 +33,8 @@ try {
}
ok(isOK, "navigator.buildID should never throw");
is(typeof(contentBuildID), "string", "navigator.buildID should be a string");
ok(+contentBuildID > LEGACY_BUILD_ID,
`navigator.buildID should be exposed in content - got "${contentBuildID}"`);
is(+contentBuildID, LEGACY_BUILD_ID,
"navigator.buildID should be spoofed in content");
//
// Access navigator.buildID from chrome.