Bug 1534538 - Principal serialization should not serialize base domain if not needed, r=Ehsan

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrea Marchesini 2019-03-29 19:20:52 +00:00
parent 6a4e37ae32
commit ac66f432bc
3 changed files with 13 additions and 6 deletions

View File

@ -206,7 +206,8 @@ nsresult PopulateContentSecurityPolicies(
}
nsresult PrincipalToPrincipalInfo(nsIPrincipal* aPrincipal,
PrincipalInfo* aPrincipalInfo) {
PrincipalInfo* aPrincipalInfo,
bool aSkipBaseDomain) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aPrincipal);
MOZ_ASSERT(aPrincipalInfo);
@ -248,7 +249,7 @@ nsresult PrincipalToPrincipalInfo(nsIPrincipal* aPrincipal,
PrincipalInfo info;
for (auto& prin : expanded->AllowList()) {
rv = PrincipalToPrincipalInfo(prin, &info);
rv = PrincipalToPrincipalInfo(prin, &info, aSkipBaseDomain);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -313,9 +314,13 @@ nsresult PrincipalToPrincipalInfo(nsIPrincipal* aPrincipal,
// This attribute is not crucial.
nsCString baseDomain;
if (NS_FAILED(aPrincipal->GetBaseDomain(baseDomain))) {
NS_WARNING("Failed to get base domain!");
if (aSkipBaseDomain) {
baseDomain.SetIsVoid(true);
} else {
if (NS_FAILED(aPrincipal->GetBaseDomain(baseDomain))) {
NS_WARNING("Failed to get base domain!");
baseDomain.SetIsVoid(true);
}
}
*aPrincipalInfo =

View File

@ -80,7 +80,8 @@ nsresult PopulateContentSecurityPolicies(
* MUST be called on the main thread only.
*/
nsresult PrincipalToPrincipalInfo(nsIPrincipal* aPrincipal,
PrincipalInfo* aPrincipalInfo);
PrincipalInfo* aPrincipalInfo,
bool aSkipBaseDomain = false);
/**
* Return true if this PrincipalInfo is a content principal and it has

View File

@ -167,7 +167,8 @@ void CookieSettings::Serialize(CookieSettingsArgs& aData) {
}
PrincipalInfo principalInfo;
rv = PrincipalToPrincipalInfo(principal, &principalInfo);
rv = PrincipalToPrincipalInfo(principal, &principalInfo,
true /* aSkipBaseDomain */);
if (NS_WARN_IF(NS_FAILED(rv))) {
continue;
}