Bug 943460 - Apps only set CSP once. r=grobinson, r=sstamm

--HG--
extra : rebase_source : 106af498bfd3314f6aaba061b81729ca43633a7e
This commit is contained in:
Deian Stefan 2013-12-07 17:43:11 -08:00
Родитель a27ca0264c
Коммит 192c9be22b
1 изменённых файлов: 31 добавлений и 8 удалений

Просмотреть файл

@ -2645,6 +2645,33 @@ nsDocument::InitCSP(nsIChannel* aChannel)
#endif
nsresult rv;
// If Document is an app check to see if we already set CSP and return early
// if that is indeed the case.
//
// In general (see bug 947831), we should not be setting CSP on a principal
// that aliases another document. For non-app code this is not a problem
// since we only share the underlying principal with nested browsing
// contexts for which a header cannot be set (e.g., about:blank and
// about:srcodoc iframes) and thus won't try to set the CSP again. This
// check ensures that we do not try to set CSP for an app.
if (applyAppDefaultCSP || applyAppManifestCSP) {
nsCOMPtr<nsIContentSecurityPolicy> csp;
rv = principal->GetCsp(getter_AddRefs(csp));
NS_ENSURE_SUCCESS(rv, rv);
if (csp) {
#ifdef PR_LOGGING
PR_LOG(gCspPRLog, PR_LOG_DEBUG, ("%s %s %s",
"This document is sharing principal with another document.",
"Since the document is an app, CSP was already set.",
"Skipping attempt to set CSP."));
#endif
return NS_OK;
}
}
// create new CSP object
csp = do_CreateInstance("@mozilla.org/contentsecuritypolicy;1", &rv);
if (NS_FAILED(rv)) {
@ -2724,16 +2751,12 @@ nsDocument::InitCSP(nsIChannel* aChannel)
}
}
if (csp) {
// Copy into principal
nsIPrincipal* principal = GetPrincipal();
rv = principal->SetCsp(csp);
NS_ENSURE_SUCCESS(rv, rv);
rv = principal->SetCsp(csp);
NS_ENSURE_SUCCESS(rv, rv);
#ifdef PR_LOGGING
PR_LOG(gCspPRLog, PR_LOG_DEBUG,
("Inserted CSP into principal %p", principal));
PR_LOG(gCspPRLog, PR_LOG_DEBUG,
("Inserted CSP into principal %p", principal));
#endif
}
return NS_OK;
}