From 99cf3b886d7b4b1698a218c0c6b4a40c771cee67 Mon Sep 17 00:00:00 2001 From: Tim Huang Date: Wed, 2 Jun 2021 19:46:20 +0000 Subject: [PATCH] Bug 1706615 - Part 2: Add UnstrippedURI in the nsDocShellLoadState. r=smaug This patch adds an attribute UnstrippedURI in the nsDocShellLoadState. The attribute will be set if the query stripping was happening. Otherwise, it will stay a nullptr. This attribute will be propagated to the loadInfo, so that we can revert the query stripping in the parent process if the loading URI is in the content blocking allow list. We can only revert the query stripping in the parent process because we cannot access the permission of the content blocking allow list of a cross-origin domain. So, we can only carry the unstripped URI in the loadInfo and perform a interal redirect to revert the query stripping. Differential Revision: https://phabricator.services.mozilla.com/D116109 --- docshell/base/nsDocShellLoadState.cpp | 7 ++++++- docshell/base/nsDocShellLoadState.h | 6 ++++++ dom/ipc/DOMTypes.ipdlh | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/docshell/base/nsDocShellLoadState.cpp b/docshell/base/nsDocShellLoadState.cpp index 7122c2769119..bd454271f66b 100644 --- a/docshell/base/nsDocShellLoadState.cpp +++ b/docshell/base/nsDocShellLoadState.cpp @@ -86,6 +86,7 @@ nsDocShellLoadState::nsDocShellLoadState( mLoadingSessionHistoryInfo = MakeUnique( aLoadState.loadingSessionHistoryInfo().ref()); } + mUnstrippedURI = aLoadState.UnstrippedURI(); } nsDocShellLoadState::nsDocShellLoadState(const nsDocShellLoadState& aOther) @@ -130,7 +131,8 @@ nsDocShellLoadState::nsDocShellLoadState(const nsDocShellLoadState& aOther) mCancelContentJSEpoch(aOther.mCancelContentJSEpoch), mLoadIdentifier(aOther.mLoadIdentifier), mChannelInitialized(aOther.mChannelInitialized), - mIsMetaRefresh(aOther.mIsMetaRefresh) { + mIsMetaRefresh(aOther.mIsMetaRefresh), + mUnstrippedURI(aOther.mUnstrippedURI) { if (aOther.mLoadingSessionHistoryInfo) { mLoadingSessionHistoryInfo = MakeUnique( *aOther.mLoadingSessionHistoryInfo); @@ -1018,5 +1020,8 @@ DocShellLoadStateInit nsDocShellLoadState::Serialize() { if (mLoadingSessionHistoryInfo) { loadState.loadingSessionHistoryInfo().emplace(*mLoadingSessionHistoryInfo); } + loadState.UnstrippedURI() = mUnstrippedURI; return loadState; } + +nsIURI* nsDocShellLoadState::GetUnstrippedURI() const { return mUnstrippedURI; } diff --git a/docshell/base/nsDocShellLoadState.h b/docshell/base/nsDocShellLoadState.h index 08f6e1e404c5..7684b4f0ea5e 100644 --- a/docshell/base/nsDocShellLoadState.h +++ b/docshell/base/nsDocShellLoadState.h @@ -247,6 +247,8 @@ class nsDocShellLoadState final { void SetFileName(const nsAString& aFileName); + nsIURI* GetUnstrippedURI() const; + // Give the type of DocShell we're loading into (chrome/content/etc) and // origin attributes for the URI we're loading, figure out if we should // inherit our principal from the document the load was requested from, or @@ -517,6 +519,10 @@ class nsDocShellLoadState final { // True if the load was triggered by a meta refresh. bool mIsMetaRefresh; + + // The original URI before query stripping happened. If it's present, it shows + // the query stripping happened. Otherwise, it will be a nullptr. + nsCOMPtr mUnstrippedURI; }; #endif /* nsDocShellLoadState_h__ */ diff --git a/dom/ipc/DOMTypes.ipdlh b/dom/ipc/DOMTypes.ipdlh index 819f5e0fd1fc..38efbe357823 100644 --- a/dom/ipc/DOMTypes.ipdlh +++ b/dom/ipc/DOMTypes.ipdlh @@ -301,6 +301,8 @@ struct DocShellLoadStateInit LoadingSessionHistoryInfo? loadingSessionHistoryInfo; bool IsMetaRefresh; + + nsIURI UnstrippedURI; }; struct TimedChannelInfo