Bug 1706615 - Part 1: Add a UnstrippedURI into the LoadInfo. r=valentin,necko-reviewers

This patch adds a UnstrippedURI into the LoadInfo. This attribute
represents the channel's URI has been stripped if this attributes is not
a nullptr.

Having this attribute allows us to be able to revert the query stripping
in the case where the loading channel is in the content blocking allow
list in the parent process.

In addition, this patch removes the main thread assertion in URIUtils
given that we've made the URL construction thread-safe. This will allow
us to be able to use nsIURI directly in ParentLoadInfoForwarderArgs.

Differential Revision: https://phabricator.services.mozilla.com/D116108
This commit is contained in:
Tim Huang 2021-06-02 19:46:19 +00:00
Родитель 971c85bc4e
Коммит d7220a241a
7 изменённых файлов: 52 добавлений и 14 удалений

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

@ -499,6 +499,9 @@ nsresult LoadInfoToLoadInfoArgs(nsILoadInfo* aLoadInfo,
maybeCspToInheritInfo.emplace(cspToInheritInfo);
}
nsCOMPtr<nsIURI> unstrippedURI;
Unused << aLoadInfo->GetUnstrippedURI(getter_AddRefs(unstrippedURI));
*aOptionalLoadInfoArgs = Some(LoadInfoArgs(
loadingPrincipalInfo, triggeringPrincipalInfo, principalToInheritInfo,
sandboxedLoadingPrincipalInfo, topLevelPrincipalInfo,
@ -540,7 +543,8 @@ nsresult LoadInfoToLoadInfoArgs(nsILoadInfo* aLoadInfo,
aLoadInfo->GetIsMediaRequest(), aLoadInfo->GetIsMediaInitialRequest(),
cookieJarSettingsArgs, aLoadInfo->GetRequestBlockingReason(),
maybeCspToInheritInfo, aLoadInfo->GetHasStoragePermission(),
aLoadInfo->GetIsMetaRefresh(), aLoadInfo->GetLoadingEmbedderPolicy()));
aLoadInfo->GetIsMetaRefresh(), aLoadInfo->GetLoadingEmbedderPolicy(),
unstrippedURI));
return NS_OK;
}
@ -797,7 +801,7 @@ nsresult LoadInfoArgsToLoadInfo(
loadInfoArgs.isInDevToolsContext(), loadInfoArgs.parserCreatedScript(),
loadInfoArgs.hasStoragePermission(), loadInfoArgs.isMetaRefresh(),
loadInfoArgs.requestBlockingReason(), loadingContext,
loadInfoArgs.loadingEmbedderPolicy());
loadInfoArgs.loadingEmbedderPolicy(), loadInfoArgs.unstrippedURI());
if (loadInfoArgs.isFromProcessingFrameAttributes()) {
loadInfo->SetIsFromProcessingFrameAttributes();
@ -839,6 +843,9 @@ void LoadInfoToParentLoadInfoForwarder(
cookieJarSettingsArgs = Some(args);
}
nsCOMPtr<nsIURI> unstrippedURI;
Unused << aLoadInfo->GetUnstrippedURI(getter_AddRefs(unstrippedURI));
*aForwarderArgsOut = ParentLoadInfoForwarderArgs(
aLoadInfo->GetAllowInsecureRedirectToDataURI(), ipcController, tainting,
aLoadInfo->GetSkipContentSniffing(), aLoadInfo->GetHttpsOnlyStatus(),
@ -852,7 +859,7 @@ void LoadInfoToParentLoadInfoForwarder(
cookieJarSettingsArgs, aLoadInfo->GetRequestBlockingReason(),
aLoadInfo->GetHasStoragePermission(), aLoadInfo->GetIsMetaRefresh(),
aLoadInfo->GetIsThirdPartyContextToTopWindow(),
aLoadInfo->GetIsInThirdPartyContext());
aLoadInfo->GetIsInThirdPartyContext(), unstrippedURI);
}
nsresult MergeParentLoadInfoForwarder(
@ -936,6 +943,9 @@ nsresult MergeParentLoadInfoForwarder(
aForwarderArgs.isInThirdPartyContext());
NS_ENSURE_SUCCESS(rv, rv);
rv = aLoadInfo->SetUnstrippedURI(aForwarderArgs.unstrippedURI());
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}

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

@ -40,7 +40,6 @@ namespace mozilla {
namespace ipc {
void SerializeURI(nsIURI* aURI, URIParams& aParams) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aURI);
aURI->Serialize(aParams);
@ -50,8 +49,6 @@ void SerializeURI(nsIURI* aURI, URIParams& aParams) {
}
void SerializeURI(nsIURI* aURI, Maybe<URIParams>& aParams) {
MOZ_ASSERT(NS_IsMainThread());
if (aURI) {
URIParams params;
SerializeURI(aURI, params);
@ -62,8 +59,6 @@ void SerializeURI(nsIURI* aURI, Maybe<URIParams>& aParams) {
}
already_AddRefed<nsIURI> DeserializeURI(const URIParams& aParams) {
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIURIMutator> mutator;
switch (aParams.type()) {
@ -132,8 +127,6 @@ already_AddRefed<nsIURI> DeserializeURI(const URIParams& aParams) {
}
already_AddRefed<nsIURI> DeserializeURI(const Maybe<URIParams>& aParams) {
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIURI> uri;
if (aParams.isSome()) {

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

@ -595,7 +595,8 @@ LoadInfo::LoadInfo(const LoadInfo& rhs)
mIsFromProcessingFrameAttributes(rhs.mIsFromProcessingFrameAttributes),
mIsMediaRequest(rhs.mIsMediaRequest),
mIsMediaInitialRequest(rhs.mIsMediaInitialRequest),
mLoadingEmbedderPolicy(rhs.mLoadingEmbedderPolicy) {}
mLoadingEmbedderPolicy(rhs.mLoadingEmbedderPolicy),
mUnstrippedURI(rhs.mUnstrippedURI) {}
LoadInfo::LoadInfo(
nsIPrincipal* aLoadingPrincipal, nsIPrincipal* aTriggeringPrincipal,
@ -635,7 +636,8 @@ LoadInfo::LoadInfo(
bool aIsInDevToolsContext, bool aParserCreatedScript,
bool aHasStoragePermission, bool aIsMetaRefresh,
uint32_t aRequestBlockingReason, nsINode* aLoadingContext,
nsILoadInfo::CrossOriginEmbedderPolicy aLoadingEmbedderPolicy)
nsILoadInfo::CrossOriginEmbedderPolicy aLoadingEmbedderPolicy,
nsIURI* aUnstrippedURI)
: mLoadingPrincipal(aLoadingPrincipal),
mTriggeringPrincipal(aTriggeringPrincipal),
mPrincipalToInherit(aPrincipalToInherit),
@ -703,7 +705,8 @@ LoadInfo::LoadInfo(
mIsFromProcessingFrameAttributes(false),
mIsMediaRequest(false),
mIsMediaInitialRequest(false),
mLoadingEmbedderPolicy(aLoadingEmbedderPolicy) {
mLoadingEmbedderPolicy(aLoadingEmbedderPolicy),
mUnstrippedURI(aUnstrippedURI) {
// Only top level TYPE_DOCUMENT loads can have a null loadingPrincipal
MOZ_ASSERT(mLoadingPrincipal ||
aContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT);
@ -1717,6 +1720,18 @@ LoadInfo::GetRequestBlockingReason(uint32_t* aReason) {
return NS_OK;
}
NS_IMETHODIMP
LoadInfo::GetUnstrippedURI(nsIURI** aURI) {
*aURI = do_AddRef(mUnstrippedURI).take();
return NS_OK;
}
NS_IMETHODIMP
LoadInfo::SetUnstrippedURI(nsIURI* aURI) {
mUnstrippedURI = aURI;
return NS_OK;
}
void LoadInfo::SetClientInfo(const ClientInfo& aClientInfo) {
mClientInfo.emplace(aClientInfo);
}

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

@ -222,7 +222,8 @@ class LoadInfo final : public nsILoadInfo {
bool aIsInDevToolsContext, bool aParserCreatedScript,
bool aHasStoragePermission, bool aIsMetaRefresh,
uint32_t aRequestBlockingReason, nsINode* aLoadingContext,
nsILoadInfo::CrossOriginEmbedderPolicy aLoadingEmbedderPolicy);
nsILoadInfo::CrossOriginEmbedderPolicy aLoadingEmbedderPolicy,
nsIURI* aUnstrippedURI);
LoadInfo(const LoadInfo& rhs);
NS_IMETHOD GetRedirects(JSContext* aCx,
@ -340,6 +341,8 @@ class LoadInfo final : public nsILoadInfo {
// See https://wicg.github.io/cross-origin-embedder-policy/#corp-check.
nsILoadInfo::CrossOriginEmbedderPolicy mLoadingEmbedderPolicy =
nsILoadInfo::EMBEDDER_POLICY_NULL;
nsCOMPtr<nsIURI> mUnstrippedURI;
};
} // namespace net

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

@ -706,5 +706,13 @@ TRRLoadInfo::SetLoadingEmbedderPolicy(
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
TRRLoadInfo::GetUnstrippedURI(nsIURI** aURI) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
TRRLoadInfo::SetUnstrippedURI(nsIURI* aURI) { return NS_ERROR_NOT_IMPLEMENTED; }
} // namespace net
} // namespace mozilla

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

@ -1372,4 +1372,10 @@ interface nsILoadInfo : nsISupports
* element and it's an initial request.
*/
[infallible] attribute boolean isMediaInitialRequest;
/**
* If this is non-null, this property holds the URI as it was before query
* stripping was performed.
*/
attribute nsIURI unstrippedURI;
};

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

@ -159,6 +159,7 @@ struct LoadInfoArgs
bool hasStoragePermission;
bool isMetaRefresh;
CrossOriginEmbedderPolicy loadingEmbedderPolicy;
nsIURI unstrippedURI;
};
/**
@ -229,6 +230,8 @@ struct ParentLoadInfoForwarderArgs
bool isInThirdPartyContext;
nsIURI unstrippedURI;
// IMPORTANT: when you add new properites here you must also update
// LoadInfoToParentLoadInfoForwarder and MergeParentLoadInfoForwarder
// in BackgroundUtils.cpp/.h!