From 34a901430db902205796bf4e0f674f4cc9bc2ea2 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Sun, 14 Jun 2026 10:08:17 +0200 Subject: [PATCH] Issue #3122 - Exclude local resources from CSP checks. This avoids local-resource URLs being restricted/nullified by remote CSP. This aligns the CSP handling with direct requests. Resolves #3122 --- dom/html/HTMLSharedElement.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dom/html/HTMLSharedElement.cpp b/dom/html/HTMLSharedElement.cpp index 1464889686..5153b517fb 100644 --- a/dom/html/HTMLSharedElement.cpp +++ b/dom/html/HTMLSharedElement.cpp @@ -18,6 +18,8 @@ #include "nsContentUtils.h" #include "nsIContentSecurityPolicy.h" #include "nsIURI.h" +#include "nsNetUtil.h" +#include "nsIProtocolHandler.h" NS_IMPL_NS_NEW_HTML_ELEMENT(Shared) @@ -186,6 +188,8 @@ SetBaseURIUsingFirstBaseWithHref(nsIDocument* aDocument, nsIContent* aMustMatch) newBaseURI = nullptr; } if (csp && newBaseURI) { + bool isLocalResource = false; + rv = NS_URIChainHasFlags(newBaseURI, nsIProtocolHandler::URI_IS_LOCAL_RESOURCE, &isLocalResource); // base-uri is only enforced if explicitly defined in the // policy - do *not* consult default-src, see: // http://www.w3.org/TR/CSP2/#directive-default-src @@ -193,7 +197,7 @@ SetBaseURIUsingFirstBaseWithHref(nsIDocument* aDocument, nsIContent* aMustMatch) rv = csp->Permits(newBaseURI, nsIContentSecurityPolicy::BASE_URI_DIRECTIVE, true /* aSpecific */, true /* aSendViolationReports */, &cspPermitsBaseURI); - if (NS_FAILED(rv) || !cspPermitsBaseURI) { + if ((NS_FAILED(rv) || !cspPermitsBaseURI) && !isLocalResource) { newBaseURI = nullptr; } }