Bug 1374612 - CSP: Hide nonce values from the DOM. r=smaug,annevk
Differential Revision: https://phabricator.services.mozilla.com/D62811
This commit is contained in:
@@ -323,11 +323,13 @@ nsresult ScriptLoader::CheckContentPolicy(Document* aDocument,
|
||||
// snapshot the nonce at load start time for performing CSP checks
|
||||
if (contentPolicyType == nsIContentPolicy::TYPE_INTERNAL_SCRIPT ||
|
||||
contentPolicyType == nsIContentPolicy::TYPE_INTERNAL_MODULE) {
|
||||
nsCOMPtr<Element> element = do_QueryInterface(aContext);
|
||||
if (element && element->IsHTMLElement()) {
|
||||
nsAutoString cspNonce;
|
||||
element->GetAttr(nsGkAtoms::nonce, cspNonce);
|
||||
secCheckLoadInfo->SetCspNonce(cspNonce);
|
||||
nsCOMPtr<nsINode> node = do_QueryInterface(aContext);
|
||||
if (node) {
|
||||
nsString* cspNonce =
|
||||
static_cast<nsString*>(node->GetProperty(nsGkAtoms::nonce));
|
||||
if (cspNonce) {
|
||||
secCheckLoadInfo->SetCspNonce(*cspNonce);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1322,12 +1324,13 @@ nsresult ScriptLoader::StartLoad(ScriptLoadRequest* aRequest) {
|
||||
// snapshot the nonce at load start time for performing CSP checks
|
||||
if (contentPolicyType == nsIContentPolicy::TYPE_INTERNAL_SCRIPT ||
|
||||
contentPolicyType == nsIContentPolicy::TYPE_INTERNAL_MODULE) {
|
||||
nsCOMPtr<Element> element = do_QueryInterface(context);
|
||||
if (element && element->IsHTMLElement()) {
|
||||
nsAutoString cspNonce;
|
||||
element->GetAttr(nsGkAtoms::nonce, cspNonce);
|
||||
nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
|
||||
loadInfo->SetCspNonce(cspNonce);
|
||||
if (context) {
|
||||
nsString* cspNonce =
|
||||
static_cast<nsString*>(context->GetProperty(nsGkAtoms::nonce));
|
||||
if (cspNonce) {
|
||||
nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
|
||||
loadInfo->SetCspNonce(*cspNonce);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1497,7 +1500,14 @@ static bool CSPAllowsInlineScript(nsIScriptElement* aElement,
|
||||
// query the nonce
|
||||
nsCOMPtr<Element> scriptContent = do_QueryInterface(aElement);
|
||||
nsAutoString nonce;
|
||||
scriptContent->GetAttr(kNameSpaceID_None, nsGkAtoms::nonce, nonce);
|
||||
if (scriptContent) {
|
||||
nsString* cspNonce =
|
||||
static_cast<nsString*>(scriptContent->GetProperty(nsGkAtoms::nonce));
|
||||
if (cspNonce) {
|
||||
nonce = *cspNonce;
|
||||
}
|
||||
}
|
||||
|
||||
bool parserCreated =
|
||||
aElement->GetParserCreated() != mozilla::dom::NOT_FROM_PARSER;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user