Bug 1315905 - Cleanup Necko http security check - part 1, r=valentin

This commit is contained in:
Andrea Marchesini 2016-11-17 14:52:16 +01:00
parent 2c792af8f0
commit d5b0cbe35a
6 changed files with 59 additions and 33 deletions

View File

@ -192,6 +192,18 @@ OriginAttributes::CreateSuffix(nsACString& aStr) const
#endif
}
void
OriginAttributes::CreateAnonymizedSuffix(nsACString& aStr) const
{
OriginAttributes attrs = *this;
if (!attrs.mFirstPartyDomain.IsEmpty()) {
attrs.mFirstPartyDomain.AssignLiteral("_anonymizedFirstPartyDomain_");
}
attrs.CreateSuffix(aStr);
}
namespace {
class MOZ_STACK_CLASS PopulateFromSuffixIterator final

View File

@ -48,12 +48,16 @@ public:
// |!key1=value1&key2=value2|. If there are no non-default attributes, this
// returns an empty string.
void CreateSuffix(nsACString& aStr) const;
// Don't use this method for anything else than debugging!
void CreateAnonymizedSuffix(nsACString& aStr) const;
MOZ_MUST_USE bool PopulateFromSuffix(const nsACString& aStr);
// Populates the attributes from a string like
// |uri!key1=value1&key2=value2| and returns the uri without the suffix.
MOZ_MUST_USE bool PopulateFromOrigin(const nsACString& aOrigin,
nsACString& aOriginNoSuffix);
nsACString& aOriginNoSuffix);
// Helper function to match mIsPrivateBrowsing to existing private browsing
// flags. Once all other flags are removed, this can be removed too.

View File

@ -174,6 +174,13 @@ ChromeUtils::FillNonDefaultOriginAttributes(dom::GlobalObject& aGlobal,
ChromeUtils::IsOriginAttributesEqual(dom::GlobalObject& aGlobal,
const dom::OriginAttributesDictionary& aA,
const dom::OriginAttributesDictionary& aB)
{
return IsOriginAttributesEqual(aA, aB);
}
/* static */ bool
ChromeUtils::IsOriginAttributesEqual(const dom::OriginAttributesDictionary& aA,
const dom::OriginAttributesDictionary& aB)
{
return aA.mAddonId == aB.mAddonId &&
aA.mAppId == aB.mAppId &&

View File

@ -88,6 +88,10 @@ public:
const dom::OriginAttributesDictionary& aA,
const dom::OriginAttributesDictionary& aB);
static bool
IsOriginAttributesEqual(const dom::OriginAttributesDictionary& aA,
const dom::OriginAttributesDictionary& aB);
static bool
IsOriginAttributesEqualIgnoringAddonId(const dom::OriginAttributesDictionary& aA,
const dom::OriginAttributesDictionary& aB);

View File

@ -24,6 +24,7 @@
#include "mozilla/net/DNSRequestParent.h"
#include "mozilla/net/ChannelDiverterParent.h"
#include "mozilla/net/IPCTransportProvider.h"
#include "mozilla/dom/ChromeUtils.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/TabContext.h"
#include "mozilla/dom/TabParent.h"
@ -46,6 +47,7 @@
using mozilla::DocShellOriginAttributes;
using mozilla::NeckoOriginAttributes;
using mozilla::dom::ChromeUtils;
using mozilla::dom::ContentParent;
using mozilla::dom::TabContext;
using mozilla::dom::TabParent;
@ -140,8 +142,8 @@ GetRequestingPrincipal(const FTPChannelCreationArgs& aArgs)
return GetRequestingPrincipal(args.loadInfo());
}
// Bug 1289001 - If GetValidatedAppInfo returns an error string, that usually
// leads to a content crash with very little info about the cause.
// Bug 1289001 - If GetValidatedOriginAttributes returns an error string, that
// usually leads to a content crash with very little info about the cause.
// We prefer to crash on the parent, so we get the reason in the crash report.
static MOZ_NORETURN MOZ_COLD
void CrashWithReason(const char * reason)
@ -153,14 +155,14 @@ void CrashWithReason(const char * reason)
}
const char*
NeckoParent::GetValidatedAppInfo(const SerializedLoadContext& aSerialized,
PContentParent* aContent,
nsIPrincipal* aRequestingPrincipal,
DocShellOriginAttributes& aAttrs)
NeckoParent::GetValidatedOriginAttributes(const SerializedLoadContext& aSerialized,
PContentParent* aContent,
nsIPrincipal* aRequestingPrincipal,
DocShellOriginAttributes& aAttrs)
{
if (!aSerialized.IsNotNull()) {
if (UsingNeckoIPCSecurity()) {
CrashWithReason("GetValidatedAppInfo | SerializedLoadContext from child is null");
CrashWithReason("GetValidatedOriginAttributes | SerializedLoadContext from child is null");
return "SerializedLoadContext from child is null";
}
@ -173,26 +175,28 @@ NeckoParent::GetValidatedAppInfo(const SerializedLoadContext& aSerialized,
nsTArray<TabContext> contextArray =
static_cast<ContentParent*>(aContent)->GetManagedTabContext();
nsAutoCString serializedSuffix;
aSerialized.mOriginAttributes.CreateAnonymizedSuffix(serializedSuffix);
nsAutoCString debugString;
for (uint32_t i = 0; i < contextArray.Length(); i++) {
TabContext tabContext = contextArray[i];
bool inBrowserElement = aSerialized.mOriginAttributes.mInIsolatedMozBrowser;
const TabContext& tabContext = contextArray[i];
if (aSerialized.mOriginAttributes.mUserContextId != tabContext.OriginAttributesRef().mUserContextId) {
if (!ChromeUtils::IsOriginAttributesEqual(aSerialized.mOriginAttributes,
tabContext.OriginAttributesRef())) {
debugString.Append("(");
debugString.AppendInt(aSerialized.mOriginAttributes.mUserContextId);
debugString.Append(serializedSuffix);
debugString.Append(",");
debugString.AppendInt(tabContext.OriginAttributesRef().mUserContextId);
nsAutoCString tabSuffix;
tabContext.OriginAttributesRef().CreateAnonymizedSuffix(tabSuffix);
debugString.Append(tabSuffix);
debugString.Append(")");
continue;
}
aAttrs = DocShellOriginAttributes();
aAttrs.mAppId = nsIScriptSecurityManager::NO_APP_ID;
aAttrs.mInIsolatedMozBrowser = inBrowserElement;
aAttrs.mUserContextId = aSerialized.mOriginAttributes.mUserContextId;
aAttrs.mPrivateBrowsingId = aSerialized.mOriginAttributes.mPrivateBrowsingId;
aAttrs.mFirstPartyDomain = aSerialized.mOriginAttributes.mFirstPartyDomain;
aAttrs = aSerialized.mOriginAttributes;
return nullptr;
}
@ -213,19 +217,14 @@ NeckoParent::GetValidatedAppInfo(const SerializedLoadContext& aSerialized,
}
}
if (contextArray.IsEmpty()) {
if (UsingNeckoIPCSecurity()) {
CrashWithReason("GetValidatedAppInfo | ContentParent does not have any PBrowsers");
return "ContentParent does not have any PBrowsers";
}
// We are running xpcshell tests
if (!UsingNeckoIPCSecurity()) {
// We are running some tests
aAttrs = aSerialized.mOriginAttributes;
return nullptr;
}
nsAutoCString errorString;
errorString.Append("GetValidatedAppInfo | App does not have permission -");
errorString.Append("GetValidatedOriginAttributes | App does not have permission -");
errorString.Append(debugString);
// Leak the buffer on the heap to make sure that it lives long enough, as
@ -244,8 +243,8 @@ NeckoParent::CreateChannelLoadContext(const PBrowserOrId& aBrowser,
nsCOMPtr<nsILoadContext> &aResult)
{
DocShellOriginAttributes attrs;
const char* error = GetValidatedAppInfo(aSerialized, aContent,
aRequestingPrincipal, attrs);
const char* error = GetValidatedOriginAttributes(aSerialized, aContent,
aRequestingPrincipal, attrs);
if (error) {
return error;
}

View File

@ -35,10 +35,10 @@ public:
MOZ_MUST_USE
static const char *
GetValidatedAppInfo(const SerializedLoadContext& aSerialized,
PContentParent* aBrowser,
nsIPrincipal* aRequestingPrincipal,
mozilla::DocShellOriginAttributes& aAttrs);
GetValidatedOriginAttributes(const SerializedLoadContext& aSerialized,
PContentParent* aBrowser,
nsIPrincipal* aRequestingPrincipal,
mozilla::DocShellOriginAttributes& aAttrs);
/*
* Creates LoadContext for parent-side of an e10s channel.