Bug 1530303 - Put CrossOriginOpenerPolicy in BrowsingContext r=nika

Differential Revision: https://phabricator.services.mozilla.com/D23935

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Valentin Gosu 2019-04-09 20:10:13 +00:00
Родитель e2ba952f6c
Коммит 06334e695a
14 изменённых файлов: 98 добавлений и 108 удалений

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

@ -131,12 +131,10 @@ already_AddRefed<BrowsingContext> BrowsingContext::Create(
context->mName = aName;
context->mOpenerId = aOpener ? aOpener->Id() : 0;
if (aParent) {
context->mCrossOriginPolicy = aParent->mCrossOriginPolicy;
} else if (aOpener) {
context->mCrossOriginPolicy = aOpener->mCrossOriginPolicy;
} else {
context->mCrossOriginPolicy = nsILoadInfo::CROSS_ORIGIN_POLICY_NULL;
BrowsingContext* inherit = aParent ? aParent : aOpener;
if (inherit) {
context->mOpenerPolicy = inherit->mOpenerPolicy;
context->mCrossOriginPolicy = inherit->mCrossOriginPolicy;
}
Register(context);

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

@ -17,6 +17,7 @@
MOZ_BC_FIELD_RACY(Name, nsString)
MOZ_BC_FIELD_RACY(Closed, bool)
MOZ_BC_FIELD(CrossOriginPolicy, nsILoadInfo::CrossOriginPolicy)
MOZ_BC_FIELD(OpenerPolicy, nsILoadInfo::CrossOriginOpenerPolicy)
// The current opener for this BrowsingContext. This is a weak reference, and
// stored as the opener ID.

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

@ -9833,11 +9833,6 @@ nsresult nsDocShell::DoURILoad(nsDocShellLoadState* aLoadState,
(contentPolicyType == nsIContentPolicy::TYPE_DOCUMENT ||
GetIsMozBrowser());
if (isTopLevelDoc && GetDocument() && GetDocument()->GetChannel()) {
nsCOMPtr<nsILoadInfo> oldLoadInfo = GetDocument()->GetChannel()->LoadInfo();
loadInfo->SetOpenerPolicy(oldLoadInfo->GetOpenerPolicy());
}
OriginAttributes attrs;
// Inherit origin attributes from PrincipalToInherit if inheritAttrs is

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

@ -18,6 +18,7 @@
#include "mozilla/dom/JSWindowActorBinding.h"
#include "mozilla/dom/JSWindowActorChild.h"
#include "mozilla/dom/JSWindowActorService.h"
#include "nsIHttpChannelInternal.h"
using namespace mozilla::ipc;
using namespace mozilla::dom::ipc;
@ -46,6 +47,17 @@ already_AddRefed<WindowGlobalChild> WindowGlobalChild::Create(
// Initalize our WindowGlobalChild object.
RefPtr<dom::BrowsingContext> bc = docshell->GetBrowsingContext();
// When creating a new window global child we also need to look at the
// channel's Cross-Origin-Opener-Policy and set it on the browsing context
// so it's available in the parent process.
nsCOMPtr<nsIHttpChannelInternal> chan =
do_QueryInterface(aWindow->GetDocument()->GetChannel());
nsILoadInfo::CrossOriginOpenerPolicy policy;
if (chan && NS_SUCCEEDED(chan->GetCrossOriginOpenerPolicy(&policy))) {
bc->SetOpenerPolicy(policy);
}
RefPtr<WindowGlobalChild> wgc = new WindowGlobalChild(aWindow, bc);
WindowGlobalInit init(principal, bc, wgc->mInnerWindowId,

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

@ -534,8 +534,7 @@ nsresult LoadInfoToLoadInfoArgs(nsILoadInfo* aLoadInfo,
aLoadInfo->GetServiceWorkerTaintingSynthesized(),
aLoadInfo->GetDocumentHasUserInteracted(),
aLoadInfo->GetDocumentHasLoaded(), cspNonce,
aLoadInfo->GetIsFromProcessingFrameAttributes(),
aLoadInfo->GetOpenerPolicy(), cookieSettingsArgs));
aLoadInfo->GetIsFromProcessingFrameAttributes(), cookieSettingsArgs));
return NS_OK;
}
@ -692,8 +691,6 @@ nsresult LoadInfoArgsToLoadInfo(
loadInfo->SetIsFromProcessingFrameAttributes();
}
loadInfo->SetOpenerPolicy(loadInfoArgs.openerPolicy());
loadInfo.forget(outLoadInfo);
return NS_OK;
}
@ -706,7 +703,7 @@ void LoadInfoToParentLoadInfoForwarder(
false, // serviceWorkerTaintingSynthesized
false, // documentHasUserInteracted
false, // documentHasLoaded
nsILoadInfo::OPENER_POLICY_NULL, Maybe<CookieSettingsArgs>());
Maybe<CookieSettingsArgs>());
return;
}
@ -719,9 +716,6 @@ void LoadInfoToParentLoadInfoForwarder(
uint32_t tainting = nsILoadInfo::TAINTING_BASIC;
Unused << aLoadInfo->GetTainting(&tainting);
nsILoadInfo::CrossOriginOpenerPolicy openerPolicy =
aLoadInfo->GetOpenerPolicy();
Maybe<CookieSettingsArgs> cookieSettingsArgs;
nsCOMPtr<nsICookieSettings> cookieSettings;
@ -737,7 +731,7 @@ void LoadInfoToParentLoadInfoForwarder(
aLoadInfo->GetAllowInsecureRedirectToDataURI(), ipcController, tainting,
aLoadInfo->GetServiceWorkerTaintingSynthesized(),
aLoadInfo->GetDocumentHasUserInteracted(),
aLoadInfo->GetDocumentHasLoaded(), openerPolicy, cookieSettingsArgs);
aLoadInfo->GetDocumentHasLoaded(), cookieSettingsArgs);
}
nsresult MergeParentLoadInfoForwarder(
@ -765,9 +759,6 @@ nsresult MergeParentLoadInfoForwarder(
aLoadInfo->MaybeIncreaseTainting(aForwarderArgs.tainting());
}
MOZ_ALWAYS_SUCCEEDS(
aLoadInfo->SetOpenerPolicy(aForwarderArgs.openerPolicy()));
MOZ_ALWAYS_SUCCEEDS(aLoadInfo->SetDocumentHasUserInteracted(
aForwarderArgs.documentHasUserInteracted()));
MOZ_ALWAYS_SUCCEEDS(

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

@ -96,8 +96,7 @@ LoadInfo::LoadInfo(
mServiceWorkerTaintingSynthesized(false),
mDocumentHasUserInteracted(false),
mDocumentHasLoaded(false),
mIsFromProcessingFrameAttributes(false),
mOpenerPolicy(nsILoadInfo::OPENER_POLICY_NULL) {
mIsFromProcessingFrameAttributes(false) {
MOZ_ASSERT(mLoadingPrincipal);
MOZ_ASSERT(mTriggeringPrincipal);
@ -356,8 +355,7 @@ LoadInfo::LoadInfo(nsPIDOMWindowOuter* aOuterWindow,
mServiceWorkerTaintingSynthesized(false),
mDocumentHasUserInteracted(false),
mDocumentHasLoaded(false),
mIsFromProcessingFrameAttributes(false),
mOpenerPolicy(nsILoadInfo::OPENER_POLICY_NULL) {
mIsFromProcessingFrameAttributes(false) {
// Top-level loads are never third-party
// Grab the information we can out of the window.
MOZ_ASSERT(aOuterWindow);
@ -471,8 +469,7 @@ LoadInfo::LoadInfo(const LoadInfo& rhs)
mDocumentHasUserInteracted(rhs.mDocumentHasUserInteracted),
mDocumentHasLoaded(rhs.mDocumentHasLoaded),
mCspNonce(rhs.mCspNonce),
mIsFromProcessingFrameAttributes(rhs.mIsFromProcessingFrameAttributes),
mOpenerPolicy(rhs.mOpenerPolicy) {}
mIsFromProcessingFrameAttributes(rhs.mIsFromProcessingFrameAttributes) {}
LoadInfo::LoadInfo(
nsIPrincipal* aLoadingPrincipal, nsIPrincipal* aTriggeringPrincipal,
@ -553,8 +550,7 @@ LoadInfo::LoadInfo(
mDocumentHasUserInteracted(aDocumentHasUserInteracted),
mDocumentHasLoaded(aDocumentHasLoaded),
mCspNonce(aCspNonce),
mIsFromProcessingFrameAttributes(false),
mOpenerPolicy(nsILoadInfo::OPENER_POLICY_NULL) {
mIsFromProcessingFrameAttributes(false) {
// Only top level TYPE_DOCUMENT loads can have a null loadingPrincipal
MOZ_ASSERT(mLoadingPrincipal ||
aContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT);
@ -1441,17 +1437,5 @@ LoadInfo::SetCspEventListener(nsICSPEventListener* aCSPEventListener) {
return NS_OK;
}
NS_IMETHODIMP
LoadInfo::GetOpenerPolicy(nsILoadInfo::CrossOriginOpenerPolicy* aOpenerPolicy) {
*aOpenerPolicy = mOpenerPolicy;
return NS_OK;
}
NS_IMETHODIMP
LoadInfo::SetOpenerPolicy(nsILoadInfo::CrossOriginOpenerPolicy aOpenerPolicy) {
mOpenerPolicy = aOpenerPolicy;
return NS_OK;
}
} // namespace net
} // namespace mozilla

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

@ -210,8 +210,6 @@ class LoadInfo final : public nsILoadInfo {
// browsing context container.
// See nsILoadInfo.isFromProcessingFrameAttributes
bool mIsFromProcessingFrameAttributes;
nsILoadInfo::CrossOriginOpenerPolicy mOpenerPolicy;
};
} // namespace net

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

@ -1092,8 +1092,6 @@ interface nsILoadInfo : nsISupports
OPENER_POLICY_SAME_SITE_ALLOW_OUTGOING = OPENER_POLICY_SAME_SITE | OPENER_POLICY_UNSAFE_ALLOW_OUTGOING_FLAG
};
[infallible] attribute nsILoadInfo_CrossOriginOpenerPolicy openerPolicy;
cenum CrossOriginPolicy : 8 {
CROSS_ORIGIN_POLICY_NULL = 0,
CROSS_ORIGIN_POLICY_ANONYMOUS = 1,

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

@ -21,7 +21,6 @@ using RequestHeaderTuples from "mozilla/net/PHttpChannelParams.h";
using struct nsHttpAtom from "nsHttp.h";
using class mozilla::net::nsHttpResponseHead from "nsHttpResponseHead.h";
using class mozilla::TimeStamp from "mozilla/TimeStamp.h";
using nsILoadInfo::CrossOriginOpenerPolicy from "ipc/IPCMessageUtils.h";
namespace mozilla {
namespace net {
@ -141,7 +140,6 @@ struct LoadInfoArgs
bool documentHasLoaded;
nsString cspNonce;
bool isFromProcessingFrameAttributes;
CrossOriginOpenerPolicy openerPolicy;
CookieSettingsArgs cookieSettings;
};
@ -175,8 +173,6 @@ struct ParentLoadInfoForwarderArgs
bool documentHasUserInteracted;
bool documentHasLoaded;
CrossOriginOpenerPolicy openerPolicy;
CookieSettingsArgs? cookieSettings;
// IMPORTANT: when you add new properites here you must also update

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

@ -624,5 +624,10 @@ void ClassifierDummyChannel::SetIPv4Disabled() {}
void ClassifierDummyChannel::SetIPv6Disabled() {}
NS_IMETHODIMP ClassifierDummyChannel::GetCrossOriginOpenerPolicy(
nsILoadInfo::CrossOriginOpenerPolicy* aPolicy) {
return NS_ERROR_NOT_IMPLEMENTED;
}
} // namespace net
} // namespace mozilla

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

@ -4564,5 +4564,59 @@ void HttpBaseChannel::SetIPv4Disabled() { mCaps |= NS_HTTP_DISABLE_IPV4; }
void HttpBaseChannel::SetIPv6Disabled() { mCaps |= NS_HTTP_DISABLE_IPV6; }
NS_IMETHODIMP HttpBaseChannel::GetCrossOriginOpenerPolicy(
nsILoadInfo::CrossOriginOpenerPolicy* aPolicy) {
if (!mResponseHead) {
return NS_ERROR_NOT_AVAILABLE;
}
nsAutoCString openerPolicy;
Unused << mResponseHead->GetHeader(nsHttp::Cross_Origin_Opener_Policy,
openerPolicy);
// Cross-Origin-Opener-Policy = sameness [ RWS outgoing ]
// sameness = %s"same-origin" / %s"same-site" ; case-sensitive
// outgoing = %s"unsafe-allow-outgoing" ; case-sensitive
Tokenizer t(openerPolicy);
nsAutoCString sameness;
nsAutoCString outgoing;
// The return value will be true if we find any whitespace. If there is
// whitespace, then it must be followed by "unsafe-allow-outgoing" otherwise
// this is a malformed header value.
bool allowOutgoing = t.ReadUntil(Tokenizer::Token::Whitespace(), sameness);
if (allowOutgoing) {
t.SkipWhites();
bool foundEOF = t.ReadUntil(Tokenizer::Token::EndOfFile(), outgoing);
if (!foundEOF) {
// Malformed response. There should be no text after the second token.
*aPolicy = nsILoadInfo::OPENER_POLICY_NULL;
return NS_OK;
}
if (!outgoing.EqualsLiteral("unsafe-allow-outgoing")) {
// Malformed response. Only one allowed value for the second token.
*aPolicy = nsILoadInfo::OPENER_POLICY_NULL;
return NS_OK;
}
}
nsILoadInfo::CrossOriginOpenerPolicy policy = nsILoadInfo::OPENER_POLICY_NULL;
if (sameness.EqualsLiteral("same-origin")) {
policy = nsILoadInfo::OPENER_POLICY_SAME_ORIGIN;
if (allowOutgoing) {
policy = nsILoadInfo::OPENER_POLICY_SAME_ORIGIN_ALLOW_OUTGOING;
}
} else if (sameness.EqualsLiteral("same-site")) {
policy = nsILoadInfo::OPENER_POLICY_SAME_SITE;
if (allowOutgoing) {
policy = nsILoadInfo::OPENER_POLICY_SAME_SITE_ALLOW_OUTGOING;
}
}
*aPolicy = policy;
return NS_OK;
}
} // namespace net
} // namespace mozilla

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

@ -317,6 +317,8 @@ class HttpBaseChannel : public nsHashPropertyBag,
NS_IMETHOD CancelByChannelClassifier(nsresult aErrorCode) override;
virtual void SetIPv4Disabled(void) override;
virtual void SetIPv6Disabled(void) override;
NS_IMETHOD GetCrossOriginOpenerPolicy(
nsILoadInfo::CrossOriginOpenerPolicy *aPolicy) override;
inline void CleanRedirectCacheChainIfNecessary() {
mRedirectedCachekeys = nullptr;

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

@ -7330,55 +7330,6 @@ nsresult nsHttpChannel::StartCrossProcessRedirect() {
return rv;
}
static nsILoadInfo::CrossOriginOpenerPolicy GetCrossOriginOpenerPolicy(
nsHttpResponseHead *responseHead) {
MOZ_ASSERT(responseHead);
nsAutoCString openerPolicy;
Unused << responseHead->GetHeader(nsHttp::Cross_Origin_Opener_Policy,
openerPolicy);
// Cross-Origin-Opener-Policy = sameness [ RWS outgoing ]
// sameness = %s"same-origin" / %s"same-site" ; case-sensitive
// outgoing = %s"unsafe-allow-outgoing" ; case-sensitive
Tokenizer t(openerPolicy);
nsAutoCString sameness;
nsAutoCString outgoing;
// The return value will be true if we find any whitespace. If there is
// whitespace, then it must be followed by "unsafe-allow-outgoing" otherwise
// this is a malformed header value.
bool allowOutgoing = t.ReadUntil(Tokenizer::Token::Whitespace(), sameness);
if (allowOutgoing) {
t.SkipWhites();
bool foundEOF = t.ReadUntil(Tokenizer::Token::EndOfFile(), outgoing);
if (!foundEOF) {
// Malformed response. There should be no text after the second token.
return nsILoadInfo::OPENER_POLICY_NULL;
}
if (!outgoing.EqualsLiteral("unsafe-allow-outgoing")) {
// Malformed response. Only one allowed value for the second token.
return nsILoadInfo::OPENER_POLICY_NULL;
}
}
nsILoadInfo::CrossOriginOpenerPolicy policy = nsILoadInfo::OPENER_POLICY_NULL;
if (sameness.EqualsLiteral("same-origin")) {
policy = nsILoadInfo::OPENER_POLICY_SAME_ORIGIN;
if (allowOutgoing) {
policy = nsILoadInfo::OPENER_POLICY_SAME_ORIGIN_ALLOW_OUTGOING;
}
} else if (sameness.EqualsLiteral("same-site")) {
policy = nsILoadInfo::OPENER_POLICY_SAME_SITE;
if (allowOutgoing) {
policy = nsILoadInfo::OPENER_POLICY_SAME_SITE_ALLOW_OUTGOING;
}
}
return policy;
}
static bool CompareCrossOriginOpenerPolicies(
nsILoadInfo::CrossOriginOpenerPolicy documentPolicy,
nsIPrincipal *documentOrigin,
@ -7435,13 +7386,14 @@ nsHttpChannel::HasCrossOriginOpenerPolicyMismatch(bool *aMismatch) {
return NS_ERROR_NOT_AVAILABLE;
}
// Get the policy of the active document, and the policy for the result.
nsILoadInfo::CrossOriginOpenerPolicy documentPolicy =
mLoadInfo->GetOpenerPolicy();
nsILoadInfo::CrossOriginOpenerPolicy resultPolicy =
GetCrossOriginOpenerPolicy(head);
RefPtr<mozilla::dom::BrowsingContext> ctx;
mLoadInfo->GetBrowsingContext(getter_AddRefs(ctx));
mLoadInfo->SetOpenerPolicy(resultPolicy);
// Get the policy of the active document, and the policy for the result.
nsILoadInfo::CrossOriginOpenerPolicy documentPolicy = ctx->GetOpenerPolicy();
nsILoadInfo::CrossOriginOpenerPolicy resultPolicy =
nsILoadInfo::OPENER_POLICY_NULL;
GetCrossOriginOpenerPolicy(&resultPolicy);
// We use the top window principal as the documentOrigin
if (!mTopWindowPrincipal) {

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

@ -4,6 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl"
#include "nsILoadInfo.idl"
%{C++
#include "nsStringFwd.h"
@ -14,7 +15,7 @@ class TimeStamp;
}
%}
[ptr] native StringArray(nsTArray<nsCString>);
[ref] native StringArrayRef(const nsTArray<nsCString>);
[ref] native CStringArrayRef(const nsTArray<nsCString>);
[ref] native securityMessagesArray(nsCOMArray<nsISecurityConsoleMessage>);
native TimeStamp(mozilla::TimeStamp);
@ -323,7 +324,7 @@ interface nsIHttpChannelInternal : nsISupports
* the CORS preflight parameters.
*/
[noscript, notxpcom, nostdcall]
void setCorsPreflightParameters(in StringArrayRef unsafeHeaders);
void setCorsPreflightParameters(in CStringArrayRef unsafeHeaders);
[noscript, notxpcom, nostdcall]
void setAltDataForChild(in boolean aIsForChild);
@ -377,4 +378,7 @@ interface nsIHttpChannelInternal : nsISupports
*/
[noscript, notxpcom, nostdcall]
void setIPv6Disabled();
[noscript]
nsILoadInfo_CrossOriginOpenerPolicy getCrossOriginOpenerPolicy();
};