Bug 1731982 - Part 11: Set the `IsThirdPartyContextToTopWindow` flag to the main worker script loading channel. r=asuth

When loading the main worker script, we will need to get the clientInfo
for the loading channel. However, the loading channel is created in
content processes and the `IsThirdPartyContextToTopWindow` won't be set
in this case. So, we will get an incorrect clientInfo with a wrong
foreign patitioned principal.

To resolve this, we have to set the flag in the content processes so
that we can get a correct clientInfo. The flag comes from the
workerPrivate which reflects the fact if the worker was created in a
third-party context. And the loading channel should have the same flag
as the document which creates the worker.

Differential Revision: https://phabricator.services.mozilla.com/D129060
This commit is contained in:
Tim Huang 2021-11-25 13:11:33 +00:00
Родитель e9fcc1c87e
Коммит 713d89b9ec
1 изменённых файлов: 10 добавлений и 0 удалений

Просмотреть файл

@ -51,6 +51,7 @@
#include "nsXPCOM.h"
#include "xpcpublic.h"
#include "mozilla/AntiTrackingUtils.h"
#include "mozilla/ArrayAlgorithm.h"
#include "mozilla/Assertions.h"
#include "mozilla/LoadContext.h"
@ -1103,6 +1104,15 @@ class ScriptLoaderRunnable final : public nsIRunnable, public nsINamed {
if (IsMainWorkerScript()) {
MOZ_DIAGNOSTIC_ASSERT(aLoadInfo.mReservedClientInfo.isSome());
// In order to get the correct foreign partitioned prinicpal, we need to
// set the `IsThirdPartyContextToTopWindow` to the channel's loadInfo.
// This flag reflects the fact that if the worker is created under a
// third-party context.
nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
loadInfo->SetIsThirdPartyContextToTopWindow(
mWorkerPrivate->IsThirdPartyContextToTopWindow());
rv = AddClientChannelHelper(
channel, std::move(aLoadInfo.mReservedClientInfo),
Maybe<ClientInfo>(), mWorkerPrivate->HybridEventTarget());