Skip to content

Commit

Permalink
Bug 30683: Prevent detection of locale via some *.properties
Browse files Browse the repository at this point in the history
Spoofing dom/dom.properties, layout/xmlparser.properties,
layout/MediaDocument.properties to en-US if needed.
  • Loading branch information
acatarineu committed Jun 21, 2019
1 parent df852fd commit d6e7178
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 3 deletions.
8 changes: 7 additions & 1 deletion dom/base/nsContentUtils.cpp
Expand Up @@ -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]) {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions dom/base/nsContentUtils.h
Expand Up @@ -1075,6 +1075,7 @@ class nsContentUtils {
eSECURITY_PROPERTIES,
eNECKO_PROPERTIES,
eFORMS_PROPERTIES_en_US,
eDOM_PROPERTIES_en_US,
PropertiesFile_COUNT
};
static nsresult ReportToConsole(
Expand Down
8 changes: 6 additions & 2 deletions dom/html/MediaDocument.cpp
Expand Up @@ -23,6 +23,7 @@
#include "nsServiceManagerUtils.h"
#include "nsIPrincipal.h"
#include "nsIMultiPartChannel.h"
#include "mozilla/Preferences.h"

namespace mozilla {
namespace dom {
Expand Down Expand Up @@ -112,8 +113,11 @@ nsresult MediaDocument::Init() {
nsCOMPtr<nsIStringBundleService> 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;
Expand Down
4 changes: 4 additions & 0 deletions dom/html/MediaDocument.h
Expand Up @@ -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 {

Expand Down
5 changes: 5 additions & 0 deletions parser/htmlparser/nsParserMsgUtils.cpp
Expand Up @@ -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) {
Expand All @@ -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);
}

Expand Down
4 changes: 4 additions & 0 deletions parser/htmlparser/nsParserMsgUtils.h
Expand Up @@ -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
Expand Down

0 comments on commit d6e7178

Please sign in to comment.