commit 7890c2d85217267e7740c254475f97df2bf77b72
parent 2d4f36d2806f4526c9302cf548bc0e6567d1a421
Author: pstanciu <pstanciu@mozilla.com>
Date: Tue, 2 Dec 2025 11:40:01 +0200
Revert "Bug 2002654 - Initialize about:blank policy container in edge case. r=dom-core,smaug" for causing build bustage @ nsIPrincipal::GetIsNullPrincipal
This reverts commit a7b3748dfc3d43ff7c8f32b8b6299fdb153e0c10.
Diffstat:
3 files changed, 13 insertions(+), 45 deletions(-)
diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp
@@ -6819,22 +6819,23 @@ nsresult nsDocShell::CreateAboutBlankDocumentViewer(
// same reference) otherwise modifying the new container (such as
// appending a new policy to CSP) within the new document will be
// incorrectly propagated to the opening doc.
- RefPtr<PolicyContainer> policyContainerToInherit = new PolicyContainer();
if (aPolicyContainer) {
+ RefPtr<PolicyContainer> policyContainerToInherit =
+ new PolicyContainer();
policyContainerToInherit->InitFromOther(
PolicyContainer::Cast(aPolicyContainer));
+ blankDoc->SetPolicyContainer(policyContainerToInherit);
+ nsIContentSecurityPolicy* csp =
+ PolicyContainer::GetCSP(policyContainerToInherit);
+ if (!csp) {
+ csp = new nsCSPContext();
+ policyContainerToInherit->SetCSP(csp);
+ };
+ nsresult rv = csp->SetRequestContextWithDocument(blankDoc);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
}
- blankDoc->SetPolicyContainer(policyContainerToInherit);
- nsIContentSecurityPolicy* csp =
- PolicyContainer::GetCSP(policyContainerToInherit);
- if (!csp) {
- csp = new nsCSPContext();
- policyContainerToInherit->SetCSP(csp);
- }
-
- // This call should only fail if blankDoc == nullptr. Which it isn't.
- MOZ_DIAGNOSTIC_ASSERT(
- NS_SUCCEEDED(csp->SetRequestContextWithDocument(blankDoc)));
blankDoc->SetInitialStatus(
aIsInitialDocument ? Document::InitialStatus::IsInitialUncommitted
diff --git a/docshell/test/browser/browser.toml b/docshell/test/browser/browser.toml
@@ -274,8 +274,6 @@ skip-if = [
["browser_bug1798780.js"]
-["browser_bug2002654.js"]
-
["browser_click_link_within_view_source.js"]
["browser_closewatcher_integration.js"]
diff --git a/docshell/test/browser/browser_bug2002654.js b/docshell/test/browser/browser_bug2002654.js
@@ -1,31 +0,0 @@
-"use strict";
-
-// This test makes sure that a policy container & content security policy is initialized for frontend created documents
-// see bug https://bugzilla.mozilla.org/show_bug.cgi?id=2002654
-add_task(async function test_policy_container_and_csp_in_about_blank() {
- let tab = await BrowserTestUtils.openNewForegroundTab(
- gBrowser,
- "about:blank"
- );
- try {
- await ContentTask.spawn(tab.linkedBrowser, null, function () {
- let meta = content.document.createElement("meta");
- meta.httpEquiv = "Content-Security-Policy";
- meta.content = "script-src 'none'";
- content.document.head.appendChild(meta);
- Assert.ok(
- (() => {
- try {
- content.window.eval("1 + 1");
- return false;
- } catch (ex) {
- return true;
- }
- })(),
- "CSP set for frontend created document"
- );
- });
- } finally {
- BrowserTestUtils.removeTab(tab);
- }
-});