зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1308951 - Add a pref to whitelist specific domains as SecureContexts r=ckerschb,jcj
MozReview-Commit-ID: AxihCLsBNRw --HG-- extra : rebase_source : bd2800c65af839ef67f4ca9a841f08884ac9c539
This commit is contained in:
Родитель
8b611ab64b
Коммит
ea829544cd
|
@ -169,7 +169,7 @@ DoContentSecurityChecks(nsIChannel* aChannel, nsILoadInfo* aLoadInfo)
|
|||
nsCOMPtr<nsIURI> uri;
|
||||
nsresult rv = NS_GetFinalChannelURI(aChannel, getter_AddRefs(uri));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
||||
nsContentPolicyType contentPolicyType =
|
||||
aLoadInfo->GetExternalContentPolicyType();
|
||||
nsContentPolicyType internalContentPolicyType =
|
||||
|
@ -671,5 +671,24 @@ nsContentSecurityManager::IsOriginPotentiallyTrustworthy(nsIPrincipal* aPrincipa
|
|||
*aIsTrustWorthy = true;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// If a host is not considered secure according to the default algorithm, then
|
||||
// check to see if it has been whitelisted by the user. We only apply this
|
||||
// whitelist for network resources, i.e., those with scheme "http" or "ws".
|
||||
// The pref should contain a comma-separated list of hostnames.
|
||||
if (scheme.EqualsLiteral("http") || scheme.EqualsLiteral("ws")) {
|
||||
nsAdoptingCString whitelist = Preferences::GetCString("dom.securecontext.whitelist");
|
||||
if (whitelist) {
|
||||
nsCCharSeparatedTokenizer tokenizer(whitelist, ',');
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
const nsCSubstring& allowedHost = tokenizer.nextToken();
|
||||
if (host.Equals(allowedHost)) {
|
||||
*aIsTrustWorthy = true;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,9 @@ XPCOMUtils.defineLazyServiceGetter(this, "gContentSecurityManager",
|
|||
"@mozilla.org/contentsecuritymanager;1",
|
||||
"nsIContentSecurityManager");
|
||||
|
||||
var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
|
||||
prefs.setCharPref("dom.securecontext.whitelist", "example.net,example.org");
|
||||
|
||||
add_task(function* test_isOriginPotentiallyTrustworthy() {
|
||||
for (let [uriSpec, expectedResult] of [
|
||||
["http://example.com/", false],
|
||||
|
@ -27,9 +30,14 @@ add_task(function* test_isOriginPotentiallyTrustworthy() {
|
|||
["http://127.0.0.1/", true],
|
||||
["file:///", true],
|
||||
["resource:///", true],
|
||||
["app://", true],
|
||||
["moz-extension://", true],
|
||||
["wss://example.com/", true],
|
||||
["about:config", false],
|
||||
["urn:generic", false],
|
||||
["http://example.net/", true],
|
||||
["ws://example.org/", true],
|
||||
["chrome://example.net/content/messenger.xul", false],
|
||||
]) {
|
||||
let uri = NetUtil.newURI(uriSpec);
|
||||
let principal = gScriptSecurityManager.getCodebasePrincipal(uri);
|
||||
|
|
Загрузка…
Ссылка в новой задаче