From d6e7178e3cbe4481aaa6eb40058f8e70a044fd43 Mon Sep 17 00:00:00 2001 From: Alex Catarineu Date: Thu, 20 Jun 2019 19:16:32 +0200 Subject: [PATCH] Bug 30683: Prevent detection of locale via some *.properties Spoofing dom/dom.properties, layout/xmlparser.properties, layout/MediaDocument.properties to en-US if needed. --- dom/base/nsContentUtils.cpp | 8 +++++++- dom/base/nsContentUtils.h | 1 + dom/html/MediaDocument.cpp | 8 ++++++-- dom/html/MediaDocument.h | 4 ++++ parser/htmlparser/nsParserMsgUtils.cpp | 5 +++++ parser/htmlparser/nsParserMsgUtils.h | 4 ++++ 6 files changed, 27 insertions(+), 3 deletions(-) diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index e75fe4aa6fb80..d0faf3b0a989b 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -3731,7 +3731,9 @@ static const char* gPropertiesFiles[nsContentUtils::PropertiesFile_COUNT] = { "chrome://global/locale/security/security.properties", "chrome://necko/locale/necko.properties", "resource://gre/chrome/en-US/locale/en-US/global/layout/" - "HtmlForm.properties"}; + "HtmlForm.properties", + "resource://gre/chrome/en-US/locale/en-US/global/dom/" + "dom.properties"}; /* static */ nsresult nsContentUtils::EnsureStringBundle(PropertiesFile aFile) { if (!sStringBundles[aFile]) { @@ -3771,6 +3773,8 @@ nsresult nsContentUtils::GetLocalizedString(PropertiesFile aFile, // When we spoof English, use en-US default strings in HTML forms. if (aFile == eFORMS_PROPERTIES && sSpoofEnglish == 2) { aFile = eFORMS_PROPERTIES_en_US; + } else if (aFile == eDOM_PROPERTIES && sSpoofEnglish == 2) { + aFile = eDOM_PROPERTIES_en_US; } nsresult rv = EnsureStringBundle(aFile); @@ -3788,6 +3792,8 @@ nsresult nsContentUtils::FormatLocalizedString(PropertiesFile aFile, // When we spoof English, use en-US default strings in HTML forms. if (aFile == eFORMS_PROPERTIES && sSpoofEnglish == 2) { aFile = eFORMS_PROPERTIES_en_US; + } else if (aFile == eDOM_PROPERTIES && sSpoofEnglish == 2) { + aFile = eDOM_PROPERTIES_en_US; } nsresult rv = EnsureStringBundle(aFile); diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index 473678bf525df..60f13eb9993d1 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -1075,6 +1075,7 @@ class nsContentUtils { eSECURITY_PROPERTIES, eNECKO_PROPERTIES, eFORMS_PROPERTIES_en_US, + eDOM_PROPERTIES_en_US, PropertiesFile_COUNT }; static nsresult ReportToConsole( diff --git a/dom/html/MediaDocument.cpp b/dom/html/MediaDocument.cpp index d3e8c65747302..cfce3c9642346 100644 --- a/dom/html/MediaDocument.cpp +++ b/dom/html/MediaDocument.cpp @@ -23,6 +23,7 @@ #include "nsServiceManagerUtils.h" #include "nsIPrincipal.h" #include "nsIMultiPartChannel.h" +#include "mozilla/Preferences.h" namespace mozilla { namespace dom { @@ -112,8 +113,11 @@ nsresult MediaDocument::Init() { nsCOMPtr stringService = mozilla::services::GetStringBundleService(); if (stringService) { - stringService->CreateBundle(NSMEDIADOCUMENT_PROPERTIES_URI, - getter_AddRefs(mStringBundle)); + stringService->CreateBundle( + Preferences::GetInt("privacy.spoof_english", 0) == 2 + ? NSMEDIADOCUMENT_PROPERTIES_URI_en_US + : NSMEDIADOCUMENT_PROPERTIES_URI, + getter_AddRefs(mStringBundle)); } mIsSyntheticDocument = true; diff --git a/dom/html/MediaDocument.h b/dom/html/MediaDocument.h index f52887066d103..079268e849466 100644 --- a/dom/html/MediaDocument.h +++ b/dom/html/MediaDocument.h @@ -15,6 +15,10 @@ #define NSMEDIADOCUMENT_PROPERTIES_URI \ "chrome://global/locale/layout/MediaDocument.properties" +#define NSMEDIADOCUMENT_PROPERTIES_URI_en_US \ + "resource://gre/chrome/en-US/locale/en-US/global/layout/" \ + "MediaDocument.properties" + namespace mozilla { namespace dom { diff --git a/parser/htmlparser/nsParserMsgUtils.cpp b/parser/htmlparser/nsParserMsgUtils.cpp index 3e369893d4f7c..c8000c949d0dd 100644 --- a/parser/htmlparser/nsParserMsgUtils.cpp +++ b/parser/htmlparser/nsParserMsgUtils.cpp @@ -9,6 +9,7 @@ #include "nsParserMsgUtils.h" #include "nsNetCID.h" #include "mozilla/Services.h" +#include "mozilla/Preferences.h" static nsresult GetBundle(const char* aPropFileName, nsIStringBundle** aBundle) { @@ -21,6 +22,10 @@ static nsresult GetBundle(const char* aPropFileName, mozilla::services::GetStringBundleService(); if (!stringService) return NS_ERROR_FAILURE; + if (Preferences::GetInt("privacy.spoof_english", 0) == 2 && + strcmp(aPropFileName, XMLPARSER_PROPERTIES) == 0) { + aPropFileName = XMLPARSER_PROPERTIES_en_US; + } return stringService->CreateBundle(aPropFileName, aBundle); } diff --git a/parser/htmlparser/nsParserMsgUtils.h b/parser/htmlparser/nsParserMsgUtils.h index b4ec4784d65f1..129254ed73060 100644 --- a/parser/htmlparser/nsParserMsgUtils.h +++ b/parser/htmlparser/nsParserMsgUtils.h @@ -11,6 +11,10 @@ #define XMLPARSER_PROPERTIES \ "chrome://global/locale/layout/xmlparser.properties" +#define XMLPARSER_PROPERTIES_en_US \ + "resource://gre/chrome/en-US/locale/en-US/global/layout/" \ + "xmlparser.properties" + class nsParserMsgUtils { nsParserMsgUtils(); // Currently this is not meant to be created, use the // static methods