From b169621e2efb87c635ab863c0eb84e1ce406de7a Mon Sep 17 00:00:00 2001 From: Thomas Nguyen Date: Mon, 14 Nov 2016 15:15:32 +0800 Subject: [PATCH] Bug 1264792 - Update request'referrer policy when redirect.r=bkelly,dragana. MozReview-Commit-ID: 3V6W0fuRomZ --HG-- extra : rebase_source : 4b708f9646ea42ef40c60ba0b7a86e14edf621e3 --- dom/base/nsContentUtils.cpp | 6 +- dom/cache/DBSchema.cpp | 5 +- dom/fetch/FetchDriver.cpp | 105 ++++++-------------- dom/fetch/FetchUtil.cpp | 56 +++++++++++ dom/fetch/FetchUtil.h | 13 +++ dom/fetch/InternalRequest.h | 66 ++++++++++++ dom/webidl/Request.webidl | 6 +- dom/workers/ScriptLoader.cpp | 4 +- dom/workers/ServiceWorkerPrivate.cpp | 16 +++ dom/xhr/XMLHttpRequestMainThread.cpp | 5 +- netwerk/protocol/http/HttpBaseChannel.cpp | 4 +- netwerk/protocol/http/HttpChannelChild.cpp | 36 ++++++- netwerk/protocol/http/HttpChannelChild.h | 1 + netwerk/protocol/http/HttpChannelParent.cpp | 5 + netwerk/protocol/http/HttpChannelParent.h | 2 + netwerk/protocol/http/PHttpChannel.ipdl | 4 +- 16 files changed, 243 insertions(+), 91 deletions(-) diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 3f96b2928b0f..ef43ecc84482 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -8480,10 +8480,8 @@ nsContentUtils::SetFetchReferrerURIWithPolicy(nsIPrincipal* aPrincipal, referrerURI = principalURI; } - net::ReferrerPolicy referrerPolicy = aReferrerPolicy; - if (referrerPolicy == net::RP_Default) { - referrerPolicy = aDoc->GetReferrerPolicy(); - } + net::ReferrerPolicy referrerPolicy = (aReferrerPolicy != net::RP_Unset) ? + aReferrerPolicy : net::RP_Default; return aChannel->SetReferrerWithPolicy(referrerURI, referrerPolicy); } diff --git a/dom/cache/DBSchema.cpp b/dom/cache/DBSchema.cpp index 044f06c30f12..61d6b0e38823 100644 --- a/dom/cache/DBSchema.cpp +++ b/dom/cache/DBSchema.cpp @@ -197,7 +197,10 @@ static_assert(int(ReferrerPolicy::_empty) == 0 && int(ReferrerPolicy::Origin) == 3 && int(ReferrerPolicy::Origin_when_cross_origin) == 4 && int(ReferrerPolicy::Unsafe_url) == 5 && - int(ReferrerPolicy::EndGuard_) == 6, + int(ReferrerPolicy::Same_origin) == 6 && + int(ReferrerPolicy::Strict_origin) == 7 && + int(ReferrerPolicy::Strict_origin_when_cross_origin) == 8 && + int(ReferrerPolicy::EndGuard_) == 9, "ReferrerPolicy values are as expected"); static_assert(int(RequestMode::Same_origin) == 0 && int(RequestMode::No_cors) == 1 && diff --git a/dom/fetch/FetchDriver.cpp b/dom/fetch/FetchDriver.cpp index 013fe3baf0f8..feb303898fa1 100644 --- a/dom/fetch/FetchDriver.cpp +++ b/dom/fetch/FetchDriver.cpp @@ -35,6 +35,7 @@ #include "mozilla/Unused.h" #include "Fetch.h" +#include "FetchUtil.h" #include "InternalRequest.h" #include "InternalResponse.h" @@ -260,62 +261,30 @@ FetchDriver::HttpFetch() // Set the same headers. SetRequestHeaders(httpChan); - // Step 2. Set the referrer. - nsAutoString referrer; - mRequest->GetReferrer(referrer); - - // The Referrer Policy in Request can be used to override a referrer policy - // associated with an environment settings object. - // If there's no Referrer Policy in the request, it should be inherited - // from environment. - ReferrerPolicy referrerPolicy = mRequest->ReferrerPolicy_(); net::ReferrerPolicy net_referrerPolicy = mRequest->GetEnvironmentReferrerPolicy(); - switch (referrerPolicy) { - case ReferrerPolicy::_empty: - break; - case ReferrerPolicy::No_referrer: - net_referrerPolicy = net::RP_No_Referrer; - break; - case ReferrerPolicy::No_referrer_when_downgrade: - net_referrerPolicy = net::RP_No_Referrer_When_Downgrade; - break; - case ReferrerPolicy::Origin: - net_referrerPolicy = net::RP_Origin; - break; - case ReferrerPolicy::Origin_when_cross_origin: - net_referrerPolicy = net::RP_Origin_When_Crossorigin; - break; - case ReferrerPolicy::Unsafe_url: - net_referrerPolicy = net::RP_Unsafe_URL; - break; - default: - MOZ_ASSERT_UNREACHABLE("Invalid ReferrerPolicy enum value?"); - break; + // Step 6 of + // https://fetch.spec.whatwg.org/#main-fetch + // If request's referrer policy is the empty string and request's client is + // non-null, then set request's referrer policy to request's client's + // associated referrer policy. + // Basically, "client" is not in our implementation, we use + // EnvironmentReferrerPolicy of the worker or document context + if (mRequest->ReferrerPolicy_() == ReferrerPolicy::_empty) { + mRequest->SetReferrerPolicy(net_referrerPolicy); + } + // Step 7 of + // https://fetch.spec.whatwg.org/#main-fetch + // If request’s referrer policy is the empty string, + // then set request’s referrer policy to "no-referrer-when-downgrade". + if (mRequest->ReferrerPolicy_() == ReferrerPolicy::_empty) { + mRequest->SetReferrerPolicy(net::RP_No_Referrer_When_Downgrade); } - if (referrer.EqualsLiteral(kFETCH_CLIENT_REFERRER_STR)) { - rv = nsContentUtils::SetFetchReferrerURIWithPolicy(mPrincipal, - mDocument, - httpChan, - net_referrerPolicy); - NS_ENSURE_SUCCESS(rv, rv); - } else if (referrer.IsEmpty()) { - rv = httpChan->SetReferrerWithPolicy(nullptr, net::RP_No_Referrer); - NS_ENSURE_SUCCESS(rv, rv); - } else { - // From "Determine request's Referrer" step 3 - // "If request's referrer is a URL, let referrerSource be request's - // referrer." - nsCOMPtr referrerURI; - rv = NS_NewURI(getter_AddRefs(referrerURI), referrer, nullptr, nullptr); - NS_ENSURE_SUCCESS(rv, rv); - rv = - httpChan->SetReferrerWithPolicy(referrerURI, - referrerPolicy == ReferrerPolicy::_empty ? - mRequest->GetEnvironmentReferrerPolicy() : - net_referrerPolicy); - NS_ENSURE_SUCCESS(rv, rv); - } + rv = FetchUtil::SetRequestReferrer(mPrincipal, + mDocument, + httpChan, + mRequest); + NS_ENSURE_SUCCESS(rv, rv); // Bug 1120722 - Authorization will be handled later. // Auth may require prompting, we don't support it yet. @@ -823,29 +792,15 @@ FetchDriver::AsyncOnChannelRedirect(nsIChannel* aOldChannel, net::ReferrerPolicy net_referrerPolicy = nsContentUtils::GetReferrerPolicyFromHeader(tRPHeaderValue); if (net_referrerPolicy != net::RP_Unset) { - ReferrerPolicy referrerPolicy = mRequest->ReferrerPolicy_(); - switch (net_referrerPolicy) { - case net::RP_No_Referrer: - referrerPolicy = ReferrerPolicy::No_referrer; - break; - case net::RP_No_Referrer_When_Downgrade: - referrerPolicy = ReferrerPolicy::No_referrer_when_downgrade; - break; - case net::RP_Origin: - referrerPolicy = ReferrerPolicy::Origin; - break; - case net::RP_Origin_When_Crossorigin: - referrerPolicy = ReferrerPolicy::Origin_when_cross_origin; - break; - case net::RP_Unsafe_URL: - referrerPolicy = ReferrerPolicy::Unsafe_url; - break; - default: - MOZ_ASSERT_UNREACHABLE("Invalid ReferrerPolicy value"); - break; + mRequest->SetReferrerPolicy(net_referrerPolicy); + // Should update channel's referrer policy + if (httpChannel) { + rv = FetchUtil::SetRequestReferrer(mPrincipal, + mDocument, + httpChannel, + mRequest); + NS_ENSURE_SUCCESS(rv, rv); } - - mRequest->SetReferrerPolicy(referrerPolicy); } } diff --git a/dom/fetch/FetchUtil.cpp b/dom/fetch/FetchUtil.cpp index 601d99216e90..d5f93d4880b4 100644 --- a/dom/fetch/FetchUtil.cpp +++ b/dom/fetch/FetchUtil.cpp @@ -3,8 +3,10 @@ #include "nsError.h" #include "nsIUnicodeDecoder.h" #include "nsString.h" +#include "nsIDocument.h" #include "mozilla/dom/EncodingUtils.h" +#include "mozilla/dom/InternalRequest.h" namespace mozilla { namespace dom { @@ -110,5 +112,59 @@ FetchUtil::ExtractHeader(nsACString::const_iterator& aStart, return PushOverLine(aStart, aEnd); } +// static +nsresult +FetchUtil::SetRequestReferrer(nsIPrincipal* aPrincipal, + nsIDocument* aDoc, + nsIHttpChannel* aChannel, + InternalRequest* aRequest) { + MOZ_ASSERT(NS_IsMainThread()); + + nsAutoString referrer; + aRequest->GetReferrer(referrer); + net::ReferrerPolicy policy = aRequest->GetReferrerPolicy(); + + nsresult rv = NS_OK; + if (referrer.IsEmpty()) { + // This is the case request’s referrer is "no-referrer" + rv = aChannel->SetReferrerWithPolicy(nullptr, net::RP_No_Referrer); + NS_ENSURE_SUCCESS(rv, rv); + } else if (referrer.EqualsLiteral(kFETCH_CLIENT_REFERRER_STR)) { + rv = nsContentUtils::SetFetchReferrerURIWithPolicy(aPrincipal, + aDoc, + aChannel, + policy); + NS_ENSURE_SUCCESS(rv, rv); + } else { + // From "Determine request's Referrer" step 3 + // "If request's referrer is a URL, let referrerSource be request's + // referrer." + nsCOMPtr referrerURI; + rv = NS_NewURI(getter_AddRefs(referrerURI), referrer, nullptr, nullptr); + NS_ENSURE_SUCCESS(rv, rv); + + rv = aChannel->SetReferrerWithPolicy(referrerURI, policy); + NS_ENSURE_SUCCESS(rv, rv); + } + + nsCOMPtr referrerURI; + aChannel->GetReferrer(getter_AddRefs(referrerURI)); + + // Step 8 https://fetch.spec.whatwg.org/#main-fetch + // If request’s referrer is not "no-referrer", set request’s referrer to + // the result of invoking determine request’s referrer. + if (referrerURI) { + nsAutoCString spec; + rv = referrerURI->GetSpec(spec); + NS_ENSURE_SUCCESS(rv, rv); + + aRequest->SetReferrer(NS_ConvertUTF8toUTF16(spec)); + } else { + aRequest->SetReferrer(EmptyString()); + } + + return NS_OK; +} + } // namespace dom } // namespace mozilla diff --git a/dom/fetch/FetchUtil.h b/dom/fetch/FetchUtil.h index d99aa39b44a2..7bf946eafa27 100644 --- a/dom/fetch/FetchUtil.h +++ b/dom/fetch/FetchUtil.h @@ -8,9 +8,15 @@ #include "mozilla/dom/File.h" #include "mozilla/dom/FormData.h" +class nsIPrincipal; +class nsIDocument; +class nsIHttpChannel; + namespace mozilla { namespace dom { +class InternalRequest; + class FetchUtil final { private: @@ -35,6 +41,13 @@ public: nsCString& aHeaderName, nsCString& aHeaderValue, bool* aWasEmptyHeader); + + static nsresult + SetRequestReferrer(nsIPrincipal* aPrincipal, + nsIDocument* aDoc, + nsIHttpChannel* aChannel, + InternalRequest* aRequest); + }; } // namespace dom diff --git a/dom/fetch/InternalRequest.h b/dom/fetch/InternalRequest.h index 84ee0bf69ed1..15672c7206e7 100644 --- a/dom/fetch/InternalRequest.h +++ b/dom/fetch/InternalRequest.h @@ -233,6 +233,72 @@ public: mReferrerPolicy = aReferrerPolicy; } + void + SetReferrerPolicy(net::ReferrerPolicy aReferrerPolicy) + { + switch (aReferrerPolicy) { + case net::RP_Unset: + mReferrerPolicy = ReferrerPolicy::_empty; + break; + case net::RP_No_Referrer: + mReferrerPolicy = ReferrerPolicy::No_referrer; + break; + case net::RP_No_Referrer_When_Downgrade: + mReferrerPolicy = ReferrerPolicy::No_referrer_when_downgrade; + break; + case net::RP_Origin: + mReferrerPolicy = ReferrerPolicy::Origin; + break; + case net::RP_Origin_When_Crossorigin: + mReferrerPolicy = ReferrerPolicy::Origin_when_cross_origin; + break; + case net::RP_Unsafe_URL: + mReferrerPolicy = ReferrerPolicy::Unsafe_url; + break; + case net::RP_Same_Origin: + mReferrerPolicy = ReferrerPolicy::Same_origin; + break; + case net::RP_Strict_Origin: + mReferrerPolicy = ReferrerPolicy::Strict_origin; + break; + case net::RP_Strict_Origin_When_Cross_Origin: + mReferrerPolicy = ReferrerPolicy::Strict_origin_when_cross_origin; + break; + default: + MOZ_ASSERT_UNREACHABLE("Invalid ReferrerPolicy value"); + break; + } + } + + net::ReferrerPolicy + GetReferrerPolicy() + { + switch (mReferrerPolicy) { + case ReferrerPolicy::_empty: + return net::RP_Unset; + case ReferrerPolicy::No_referrer: + return net::RP_No_Referrer; + case ReferrerPolicy::No_referrer_when_downgrade: + return net::RP_No_Referrer_When_Downgrade; + case ReferrerPolicy::Origin: + return net::RP_Origin; + case ReferrerPolicy::Origin_when_cross_origin: + return net::RP_Origin_When_Crossorigin; + case ReferrerPolicy::Unsafe_url: + return net::RP_Unsafe_URL; + case ReferrerPolicy::Strict_origin: + return net::RP_Strict_Origin; + case ReferrerPolicy::Same_origin: + return net::RP_Same_Origin; + case ReferrerPolicy::Strict_origin_when_cross_origin: + return net::RP_Strict_Origin_When_Cross_Origin; + default: + MOZ_ASSERT_UNREACHABLE("Invalid ReferrerPolicy enum value?"); + break; + } + return net::RP_Unset; + } + net::ReferrerPolicy GetEnvironmentReferrerPolicy() const { diff --git a/dom/webidl/Request.webidl b/dom/webidl/Request.webidl index e29c084d006e..138e2f055fb0 100644 --- a/dom/webidl/Request.webidl +++ b/dom/webidl/Request.webidl @@ -63,4 +63,8 @@ enum RequestMode { "same-origin", "no-cors", "cors", "navigate" }; enum RequestCredentials { "omit", "same-origin", "include" }; enum RequestCache { "default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached" }; enum RequestRedirect { "follow", "error", "manual" }; -enum ReferrerPolicy { "", "no-referrer", "no-referrer-when-downgrade", "origin", "origin-when-cross-origin", "unsafe-url" }; +enum ReferrerPolicy { + "", "no-referrer", "no-referrer-when-downgrade", "origin", + "origin-when-cross-origin", "unsafe-url", "same-origin", "strict-origin", + "strict-origin-when-cross-origin" +}; diff --git a/dom/workers/ScriptLoader.cpp b/dom/workers/ScriptLoader.cpp index 2327d505dec4..bab9bd192389 100644 --- a/dom/workers/ScriptLoader.cpp +++ b/dom/workers/ScriptLoader.cpp @@ -205,8 +205,10 @@ ChannelFromScriptURL(nsIPrincipal* principal, NS_ENSURE_SUCCESS(rv, rv); if (nsCOMPtr httpChannel = do_QueryInterface(channel)) { + mozilla::net::ReferrerPolicy referrerPolicy = parentDoc ? + parentDoc->GetReferrerPolicy() : mozilla::net::RP_Default; rv = nsContentUtils::SetFetchReferrerURIWithPolicy(principal, parentDoc, - httpChannel, mozilla::net::RP_Default); + httpChannel, referrerPolicy); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } diff --git a/dom/workers/ServiceWorkerPrivate.cpp b/dom/workers/ServiceWorkerPrivate.cpp index 0c93a0fa5e6a..132367725163 100644 --- a/dom/workers/ServiceWorkerPrivate.cpp +++ b/dom/workers/ServiceWorkerPrivate.cpp @@ -1341,12 +1341,19 @@ public: httpChannel->GetRequestHeader(NS_LITERAL_CSTRING("Referer"), referrer); if (!referrer.IsEmpty()) { mReferrer = referrer; + } else { + // If there's no referrer Header, means the header was omitted for + // security/privacy reason. + mReferrer = EmptyCString(); } uint32_t referrerPolicy = 0; rv = httpChannel->GetReferrerPolicy(&referrerPolicy); NS_ENSURE_SUCCESS(rv, rv); switch (referrerPolicy) { + case nsIHttpChannel::REFERRER_POLICY_UNSET: + mReferrerPolicy = ReferrerPolicy::_empty; + break; case nsIHttpChannel::REFERRER_POLICY_NO_REFERRER: mReferrerPolicy = ReferrerPolicy::No_referrer; break; @@ -1362,6 +1369,15 @@ public: case nsIHttpChannel::REFERRER_POLICY_UNSAFE_URL: mReferrerPolicy = ReferrerPolicy::Unsafe_url; break; + case nsIHttpChannel::REFERRER_POLICY_SAME_ORIGIN: + mReferrerPolicy = ReferrerPolicy::Same_origin; + break; + case nsIHttpChannel::REFERRER_POLICY_STRICT_ORIGIN_WHEN_XORIGIN: + mReferrerPolicy = ReferrerPolicy::Strict_origin_when_cross_origin; + break; + case nsIHttpChannel::REFERRER_POLICY_STRICT_ORIGIN: + mReferrerPolicy = ReferrerPolicy::Strict_origin; + break; default: MOZ_ASSERT_UNREACHABLE("Invalid Referrer Policy enum value?"); break; diff --git a/dom/xhr/XMLHttpRequestMainThread.cpp b/dom/xhr/XMLHttpRequestMainThread.cpp index 5dcf81bb833d..4a71de1d10de 100644 --- a/dom/xhr/XMLHttpRequestMainThread.cpp +++ b/dom/xhr/XMLHttpRequestMainThread.cpp @@ -2541,9 +2541,10 @@ XMLHttpRequestMainThread::InitiateFetch(nsIInputStream* aUploadStream, if (!IsSystemXHR()) { nsCOMPtr owner = GetOwner(); nsCOMPtr doc = owner ? owner->GetExtantDoc() : nullptr; + mozilla::net::ReferrerPolicy referrerPolicy = doc ? + doc->GetReferrerPolicy() : mozilla::net::RP_Default; nsContentUtils::SetFetchReferrerURIWithPolicy(mPrincipal, doc, - httpChannel, - mozilla::net::RP_Default); + httpChannel, referrerPolicy); } // Some extensions override the http protocol handler and provide their own diff --git a/netwerk/protocol/http/HttpBaseChannel.cpp b/netwerk/protocol/http/HttpBaseChannel.cpp index ac843e37bee8..dd1c8457a065 100644 --- a/netwerk/protocol/http/HttpBaseChannel.cpp +++ b/netwerk/protocol/http/HttpBaseChannel.cpp @@ -1288,7 +1288,7 @@ HttpBaseChannel::SetReferrerWithPolicy(nsIURI *referrer, if(NS_FAILED(rv)) { return rv; } - mReferrerPolicy = REFERRER_POLICY_NO_REFERRER_WHEN_DOWNGRADE; + mReferrerPolicy = referrerPolicy; if (!referrer) { return NS_OK; @@ -1296,7 +1296,6 @@ HttpBaseChannel::SetReferrerWithPolicy(nsIURI *referrer, // Don't send referrer at all when the meta referrer setting is "no-referrer" if (referrerPolicy == REFERRER_POLICY_NO_REFERRER) { - mReferrerPolicy = REFERRER_POLICY_NO_REFERRER; return NS_OK; } @@ -1581,7 +1580,6 @@ HttpBaseChannel::SetReferrerWithPolicy(nsIURI *referrer, if (NS_FAILED(rv)) return rv; mReferrer = clone; - mReferrerPolicy = referrerPolicy; return NS_OK; } diff --git a/netwerk/protocol/http/HttpChannelChild.cpp b/netwerk/protocol/http/HttpChannelChild.cpp index acda7f47adc5..7fa9d77e0641 100644 --- a/netwerk/protocol/http/HttpChannelChild.cpp +++ b/netwerk/protocol/http/HttpChannelChild.cpp @@ -1682,6 +1682,11 @@ HttpChannelChild::OnRedirectVerifyCallback(nsresult result) LOG(("HttpChannelChild::OnRedirectVerifyCallback [this=%p]\n", this)); nsresult rv; OptionalURIParams redirectURI; + + uint32_t referrerPolicy = REFERRER_POLICY_NO_REFERRER_WHEN_DOWNGRADE; + OptionalURIParams referrerURI; + SerializeURI(nullptr, referrerURI); + nsCOMPtr newHttpChannel = do_QueryInterface(mRedirectChannelChild); @@ -1708,6 +1713,12 @@ HttpChannelChild::OnRedirectVerifyCallback(nsresult result) forceHSTSPriming = newLoadInfo->GetForceHSTSPriming(); mixedContentWouldBlock = newLoadInfo->GetMixedContentWouldBlock(); } + + newHttpChannel->GetReferrerPolicy(&referrerPolicy); + nsCOMPtr newChannelReferrerURI; + newHttpChannel->GetReferrer(getter_AddRefs(newChannelReferrerURI)); + + SerializeURI(newChannelReferrerURI, referrerURI); } if (mRedirectingForSubsequentSynthesizedResponse) { @@ -1778,9 +1789,9 @@ HttpChannelChild::OnRedirectVerifyCallback(nsresult result) } if (mIPCOpen) - SendRedirect2Verify(result, *headerTuples, loadFlags, redirectURI, - corsPreflightArgs, forceHSTSPriming, - mixedContentWouldBlock, chooseAppcache); + SendRedirect2Verify(result, *headerTuples, loadFlags, referrerPolicy, + referrerURI, redirectURI, corsPreflightArgs, + forceHSTSPriming, mixedContentWouldBlock, chooseAppcache); return NS_OK; } @@ -2134,6 +2145,25 @@ HttpChannelChild::ContinueAsyncOpen() // HttpChannelChild::nsIHttpChannel //----------------------------------------------------------------------------- +NS_IMETHODIMP +HttpChannelChild::SetReferrerWithPolicy(nsIURI *referrer, + uint32_t referrerPolicy) +{ + ENSURE_CALLED_BEFORE_CONNECT(); + + // remove old referrer if any, loop backwards + for (int i = mClientSetRequestHeaders.Length() - 1; i >= 0; --i) { + if (NS_LITERAL_CSTRING("Referer").Equals(mClientSetRequestHeaders[i].mHeader)) { + mClientSetRequestHeaders.RemoveElementAt(i); + } + } + + nsresult rv = HttpBaseChannel::SetReferrerWithPolicy(referrer, referrerPolicy); + if (NS_FAILED(rv)) + return rv; + return NS_OK; + +} NS_IMETHODIMP HttpChannelChild::SetRequestHeader(const nsACString& aHeader, const nsACString& aValue, diff --git a/netwerk/protocol/http/HttpChannelChild.h b/netwerk/protocol/http/HttpChannelChild.h index edd209a9f13e..ecf31874db61 100644 --- a/netwerk/protocol/http/HttpChannelChild.h +++ b/netwerk/protocol/http/HttpChannelChild.h @@ -78,6 +78,7 @@ public: NS_IMETHOD AsyncOpen2(nsIStreamListener *aListener) override; // HttpBaseChannel::nsIHttpChannel + NS_IMETHOD SetReferrerWithPolicy(nsIURI *referrer, uint32_t referrerPolicy) override; NS_IMETHOD SetRequestHeader(const nsACString& aHeader, const nsACString& aValue, bool aMerge) override; diff --git a/netwerk/protocol/http/HttpChannelParent.cpp b/netwerk/protocol/http/HttpChannelParent.cpp index 672c5370d4dd..77b880fcd4c2 100644 --- a/netwerk/protocol/http/HttpChannelParent.cpp +++ b/netwerk/protocol/http/HttpChannelParent.cpp @@ -694,6 +694,8 @@ bool HttpChannelParent::RecvRedirect2Verify(const nsresult& result, const RequestHeaderTuples& changedHeaders, const uint32_t& loadFlags, + const uint32_t& referrerPolicy, + const OptionalURIParams& aReferrerURI, const OptionalURIParams& aAPIRedirectURI, const OptionalCorsPreflightArgs& aCorsPreflightArgs, const bool& aForceHSTSPriming, @@ -745,6 +747,9 @@ HttpChannelParent::RecvRedirect2Verify(const nsresult& result, } } + nsCOMPtr referrerUri = DeserializeURI(aReferrerURI); + newHttpChannel->SetReferrerWithPolicy(referrerUri, referrerPolicy); + nsCOMPtr appCacheChannel = do_QueryInterface(newHttpChannel); if (appCacheChannel) { diff --git a/netwerk/protocol/http/HttpChannelParent.h b/netwerk/protocol/http/HttpChannelParent.h index 1e5c63bdb32c..571aad012026 100644 --- a/netwerk/protocol/http/HttpChannelParent.h +++ b/netwerk/protocol/http/HttpChannelParent.h @@ -152,6 +152,8 @@ protected: virtual bool RecvRedirect2Verify(const nsresult& result, const RequestHeaderTuples& changedHeaders, const uint32_t& loadFlags, + const uint32_t& referrerPolicy, + const OptionalURIParams& aReferrerURI, const OptionalURIParams& apiRedirectUri, const OptionalCorsPreflightArgs& aCorsPreflightArgs, const bool& aForceHSTSPriming, diff --git a/netwerk/protocol/http/PHttpChannel.ipdl b/netwerk/protocol/http/PHttpChannel.ipdl index 1eb25a4039e9..01d89f46d10a 100644 --- a/netwerk/protocol/http/PHttpChannel.ipdl +++ b/netwerk/protocol/http/PHttpChannel.ipdl @@ -45,7 +45,9 @@ parent: // Reports approval/veto of redirect by child process redirect observers async Redirect2Verify(nsresult result, RequestHeaderTuples changedHeaders, - uint32_t loadFlags, OptionalURIParams apiRedirectTo, + uint32_t loadFlags, uint32_t referrerPolicy, + OptionalURIParams referrerUri, + OptionalURIParams apiRedirectTo, OptionalCorsPreflightArgs corsPreflightArgs, bool forceHSTSPriming, bool mixedContentWouldBlock, bool chooseAppcache);