From 2323f895b06021867862d2e4c104beb45754dcad Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 31 Jan 2019 15:53:24 +0000 Subject: [PATCH] Bug 1471496 part 1. Fix IsPlatformObjectSameOrigin to do the right thing when we're doing first-party isolation but turning off its effects on scripted property access. r=bholley Differential Revision: https://phabricator.services.mozilla.com/D18029 --HG-- extra : moz-landing-system : lando --- dom/base/MaybeCrossOriginObject.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/dom/base/MaybeCrossOriginObject.cpp b/dom/base/MaybeCrossOriginObject.cpp index a5c62225c21e..6c36cc9287a0 100644 --- a/dom/base/MaybeCrossOriginObject.cpp +++ b/dom/base/MaybeCrossOriginObject.cpp @@ -41,7 +41,8 @@ bool MaybeCrossOriginObjectMixins::IsPlatformObjectSameOrigin(JSContext* cx, BasePrincipal* subjectPrincipal = BasePrincipal::Cast(nsContentUtils::SubjectPrincipal(cx)); - nsIPrincipal* objectPrincipal = nsContentUtils::ObjectPrincipal(obj); + BasePrincipal* objectPrincipal = + BasePrincipal::Cast(nsContentUtils::ObjectPrincipal(obj)); // The spec effectively has an EqualsConsideringDomain check here, // because the spec has no concept of asymmetric security @@ -53,11 +54,25 @@ bool MaybeCrossOriginObjectMixins::IsPlatformObjectSameOrigin(JSContext* cx, // SubsumesConsideringDomain give the same results and use // EqualsConsideringDomain for the check we actually do, since it's // stricter and more closely matches the spec. + // + // That said, if the (not very well named) + // OriginAttributes::IsRestrictOpenerAccessForFPI() method returns + // false, we want to use FastSubsumesConsideringDomainIgnoringFPD + // instead of FastEqualsConsideringDomain, because in that case we + // still want to treat things which are in different first-party + // contexts as same-origin. MOZ_ASSERT( subjectPrincipal->FastEqualsConsideringDomain(objectPrincipal) == subjectPrincipal->FastSubsumesConsideringDomain(objectPrincipal), "Why are we in an asymmetric case here?"); - return subjectPrincipal->FastEqualsConsideringDomain(objectPrincipal); + if (OriginAttributes::IsRestrictOpenerAccessForFPI()) { + return subjectPrincipal->FastEqualsConsideringDomain(objectPrincipal); + } + + return subjectPrincipal->FastSubsumesConsideringDomainIgnoringFPD( + objectPrincipal) && + objectPrincipal->FastSubsumesConsideringDomainIgnoringFPD( + subjectPrincipal); } bool MaybeCrossOriginObjectMixins::CrossOriginGetOwnPropertyHelper(