Bug 1939538 - teach ContentPrincipal::GetSpecialBaseDomain not to bother for chrome/resource/ui URLs, r=ckerschb

Differential Revision: https://phabricator.services.mozilla.com/D233017
This commit is contained in:
Gijs Kruitbosch
2025-01-07 15:54:10 +00:00
parent 2f35a317dc
commit 1b26010b77
2 changed files with 14 additions and 0 deletions

View File

@@ -397,6 +397,15 @@ static nsresult GetSpecialBaseDomain(const nsCOMPtr<nsIURI>& aURI,
return aURI->GetSpec(aBaseDomain); return aURI->GetSpec(aBaseDomain);
} }
// For local resources we can't get a meaningful base domain.
bool isUIResource = false;
if (NS_SUCCEEDED(NS_URIChainHasFlags(
aURI, nsIProtocolHandler::URI_IS_UI_RESOURCE, &isUIResource)) &&
isUIResource) {
*aHandled = true;
return aURI->GetPrePath(aBaseDomain);
}
if (aURI->SchemeIs("indexeddb")) { if (aURI->SchemeIs("indexeddb")) {
*aHandled = true; *aHandled = true;
return aURI->GetSpec(aBaseDomain); return aURI->GetSpec(aBaseDomain);

View File

@@ -182,3 +182,8 @@ Assert.equal(
ipv6Principal.siteOriginNoSuffix, ipv6Principal.siteOriginNoSuffix,
"https://[2001:db8::ff00:42:8329]" "https://[2001:db8::ff00:42:8329]"
); );
// Checks for non-http URIs not using the TLD service.
let resourceURI = Services.io.newURI("resource://test.example.com/test");
let resourcePrincipal = scriptSecMan.createContentPrincipal(resourceURI, {});
Assert.equal(resourcePrincipal.siteOrigin, "resource://test.example.com");