From a90a5cba08fdf6c0ceb95101c275108a152a3aed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 07:35:37 +0200 Subject: Merging upstream version 127.0. Signed-off-by: Daniel Baumann --- toolkit/components/antitracking/StorageAccess.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'toolkit/components/antitracking/StorageAccess.cpp') diff --git a/toolkit/components/antitracking/StorageAccess.cpp b/toolkit/components/antitracking/StorageAccess.cpp index c18efb2b4c..9a3b6f7e2c 100644 --- a/toolkit/components/antitracking/StorageAccess.cpp +++ b/toolkit/components/antitracking/StorageAccess.cpp @@ -766,11 +766,23 @@ bool ShouldAllowAccessFor(nsIChannel* aChannel, nsIURI* aURI, RefPtr targetBC; rv = loadInfo->GetTargetBrowsingContext(getter_AddRefs(targetBC)); - if (!targetBC || NS_WARN_IF(NS_FAILED(rv))) { + if (NS_WARN_IF(NS_FAILED(rv))) { LOG(("Failed to get the channel's target browsing context")); return false; } + // If we cannot get the target browsing context from the loadInfo, the channel + // could be a fetch request from a worker scope. In this case, we get the + // target browsing context from the worker associated browsing context + // instead. + if (!targetBC) { + rv = loadInfo->GetWorkerAssociatedBrowsingContext(getter_AddRefs(targetBC)); + } + if (!targetBC || NS_WARN_IF(NS_FAILED(rv))) { + LOG(("No browsing context is available for the channel.")); + return false; + } + if (Document::StorageAccessSandboxed(targetBC->GetSandboxFlags())) { LOG(("Our document is sandboxed")); *aRejectedReason = blockedReason; -- cgit v1.2.3