Bug 1352778 - Do not reset triggeringPrincipal but only principalToInherit within loadInfo when forced to. r=gijs

This commit is contained in:
Christoph Kerschbaumer 2017-04-03 20:06:53 +02:00
parent 5a18eb392c
commit 78d8448ba5
4 changed files with 13 additions and 29 deletions

View File

@ -106,7 +106,7 @@ Converter.prototype = {
// Because content might still have a reference to this window,
// force setting it to a null principal to avoid it being same-
// origin with (other) content.
this.channel.loadInfo.resetPrincipalsToNullPrincipal();
this.channel.loadInfo.resetPrincipalToInheritToNullPrincipal();
this.listener.onStartRequest(this.channel, context);
},

View File

@ -24,18 +24,18 @@ ok(principalToInherit.startsWith("http://mochi.test:8888/"),
"initial principalToInherit correct");
// reset principals on the loadinfo
loadInfo.resetPrincipalsToNullPrincipal();
loadInfo.resetPrincipalToInheritToNullPrincipal();
// 2) verify loadInfo contains the correct principals
var triggeringPrincipal = channel.loadInfo.triggeringPrincipal;
var loadingPrincipal = channel.loadInfo.loadingPrincipal;
var principalToInherit = channel.loadInfo.principalToInherit;
triggeringPrincipal = channel.loadInfo.triggeringPrincipal.URI.asciiSpec;
loadingPrincipal = channel.loadInfo.loadingPrincipal.URI.asciiSpec;
principalToInherit = channel.loadInfo.principalToInherit;
ok(triggeringPrincipal.isNullPrincipal,
ok(triggeringPrincipal.startsWith("http://mochi.test:8888/"),
"triggeringPrincipal after resetting correct");
ok(loadingPrincipal.isNullPrincipal,
"triggeringPrincipal after resetting correct");
ok(triggeringPrincipal.isNullPrincipal,
ok(loadingPrincipal.startsWith("http://mochi.test:8888/"),
"loadingPrincipal after resetting correct");
ok(principalToInherit.isNullPrincipal,
"principalToInherit after resetting correct");
// 3) verify that getChannelResultPrincipal returns right principal

View File

@ -712,22 +712,13 @@ LoadInfo::GetScriptableOriginAttributes(JSContext* aCx,
}
NS_IMETHODIMP
LoadInfo::ResetPrincipalsToNullPrincipal()
LoadInfo::ResetPrincipalToInheritToNullPrincipal()
{
// take the originAttributes from the LoadInfo and create
// a new NullPrincipal using those origin attributes.
nsCOMPtr<nsIPrincipal> newNullPrincipal =
NullPrincipal::Create(mOriginAttributes);
MOZ_ASSERT(mInternalContentPolicyType != nsIContentPolicy::TYPE_DOCUMENT ||
!mLoadingPrincipal,
"LoadingPrincipal should be null for toplevel loads");
// the loadingPrincipal for toplevel loads is always a nullptr;
if (mInternalContentPolicyType != nsIContentPolicy::TYPE_DOCUMENT) {
mLoadingPrincipal = newNullPrincipal;
}
mTriggeringPrincipal = newNullPrincipal;
mPrincipalToInherit = newNullPrincipal;
// setting SEC_FORCE_INHERIT_PRINCIPAL_OVERRULE_OWNER will overrule

View File

@ -518,20 +518,13 @@ interface nsILoadInfo : nsISupports
[infallible] readonly attribute unsigned long long frameOuterWindowID;
/**
* For all loads of type other than TYPE_DOCUMENT this function resets the
* loadingPrincipal, the triggeringPrincipal and the
* principalToInherit to a freshly created NullPrincipal which inherits
* the current origin attributes from the loadinfo.
* For loads of TYPE_DOCUMENT this function resets only the
* TriggeringPrincipal as well as the PrincipalToInherit to a freshly
* created NullPrincipal which inherits the origin attributes from
* the loadInfo. (Please note that the loadingPrincipal for TYPE_DOCUMENT
* loads is always null.)
* Resets the PrincipalToInherit to a freshly created NullPrincipal
* which inherits the origin attributes from the loadInfo.
*
* WARNING: Please only use that function if you know exactly what
* you are doing!!!
*/
void resetPrincipalsToNullPrincipal();
void resetPrincipalToInheritToNullPrincipal();
/**
* Customized OriginAttributes within LoadInfo to allow overwriting of the