Skip to content

Commit

Permalink
Bug 1491342 - Ignore document.domain in ShouldWaiveXray. r=bholley
Browse files Browse the repository at this point in the history
We want to get rid of JS_GetCompartmentPrincipals. The origin stored in CompartmentPrivate does not account for document.domain changes because that's a per-realm thing.

Fortunately we should not have waivers in any cases that involve document.domain.

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

--HG--
extra : moz-landing-system : lando
  • Loading branch information
jandem committed Sep 21, 2018
1 parent 53a8a14 commit 4a02cf5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
21 changes: 19 additions & 2 deletions caps/BasePrincipal.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class BasePrincipal : public nsJSPrincipals
inline bool FastEqualsConsideringDomain(nsIPrincipal* aOther);
inline bool FastSubsumes(nsIPrincipal* aOther);
inline bool FastSubsumesConsideringDomain(nsIPrincipal* aOther);
inline bool FastSubsumesIgnoringFPD(nsIPrincipal* aOther);
inline bool FastSubsumesConsideringDomainIgnoringFPD(nsIPrincipal* aOther);

// Returns the principal to inherit when a caller with this principal loads
Expand Down Expand Up @@ -234,6 +235,9 @@ class BasePrincipal : public nsJSPrincipals
CreateCodebasePrincipal(nsIURI* aURI, const OriginAttributes& aAttrs,
const nsACString& aOriginNoSuffix);

inline bool FastSubsumesIgnoringFPD(nsIPrincipal* aOther,
DocumentDomainConsideration aConsideration);

RefPtr<nsAtom> mOriginNoSuffix;
RefPtr<nsAtom> mOriginSuffix;

Expand Down Expand Up @@ -317,15 +321,28 @@ BasePrincipal::FastSubsumesConsideringDomain(nsIPrincipal* aOther)
}

inline bool
BasePrincipal::FastSubsumesConsideringDomainIgnoringFPD(nsIPrincipal* aOther)
BasePrincipal::FastSubsumesIgnoringFPD(nsIPrincipal* aOther,
DocumentDomainConsideration aConsideration)
{
if (Kind() == eCodebasePrincipal &&
!dom::ChromeUtils::IsOriginAttributesEqualIgnoringFPD(
mOriginAttributes, Cast(aOther)->mOriginAttributes)) {
return false;
}

return SubsumesInternal(aOther, ConsiderDocumentDomain);
return SubsumesInternal(aOther, aConsideration);
}

inline bool
BasePrincipal::FastSubsumesIgnoringFPD(nsIPrincipal* aOther)
{
return FastSubsumesIgnoringFPD(aOther, DontConsiderDocumentDomain);
}

inline bool
BasePrincipal::FastSubsumesConsideringDomainIgnoringFPD(nsIPrincipal* aOther)
{
return FastSubsumesIgnoringFPD(aOther, ConsiderDocumentDomain);
}

} // namespace mozilla
Expand Down
10 changes: 10 additions & 0 deletions js/xpconnect/src/XPCJSRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,16 @@ CompartmentOriginInfo::Subsumes(JS::Compartment* aCompA, JS::Compartment* aCompB
return apriv->originInfo.mOrigin->FastSubsumes(bpriv->originInfo.mOrigin);
}

/* static */ bool
CompartmentOriginInfo::SubsumesIgnoringFPD(JS::Compartment* aCompA, JS::Compartment* aCompB)
{
CompartmentPrivate* apriv = CompartmentPrivate::Get(aCompA);
CompartmentPrivate* bpriv = CompartmentPrivate::Get(aCompB);
MOZ_ASSERT(apriv);
MOZ_ASSERT(bpriv);
return apriv->originInfo.mOrigin->FastSubsumesIgnoringFPD(bpriv->originInfo.mOrigin);
}

void
SetCompartmentChangedDocumentDomain(JS::Compartment* compartment)
{
Expand Down
1 change: 1 addition & 0 deletions js/xpconnect/src/xpcprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -2934,6 +2934,7 @@ class CompartmentOriginInfo

// Does the principal of compartment a subsume the principal of compartment b?
static bool Subsumes(JS::Compartment* aCompA, JS::Compartment* aCompB);
static bool SubsumesIgnoringFPD(JS::Compartment* aCompA, JS::Compartment* aCompB);

bool MightBeWebContent() const;

Expand Down
8 changes: 4 additions & 4 deletions js/xpconnect/wrappers/WrapperFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ ShouldWaiveXray(JSContext* cx, JSObject* originalObj)
bool sameOrigin = false;
if (OriginAttributes::IsRestrictOpenerAccessForFPI()) {
sameOrigin =
AccessCheck::subsumesConsideringDomain(oldCompartment, newCompartment) &&
AccessCheck::subsumesConsideringDomain(newCompartment, oldCompartment);
CompartmentOriginInfo::Subsumes(oldCompartment, newCompartment) &&
CompartmentOriginInfo::Subsumes(newCompartment, oldCompartment);
} else {
sameOrigin =
AccessCheck::subsumesConsideringDomainIgnoringFPD(oldCompartment, newCompartment) &&
AccessCheck::subsumesConsideringDomainIgnoringFPD(newCompartment, oldCompartment);
CompartmentOriginInfo::SubsumesIgnoringFPD(oldCompartment, newCompartment) &&
CompartmentOriginInfo::SubsumesIgnoringFPD(newCompartment, oldCompartment);
}
return sameOrigin;
}
Expand Down

0 comments on commit 4a02cf5

Please sign in to comment.