Bug 1209843 - Stop checking for UNKNOWN_APP_ID in all places except those where AppId() is explicitly queried. r=sicking

This commit is contained in:
Bobby Holley 2015-09-29 19:42:21 -07:00
parent 0d9ce94418
commit e819c34953
4 changed files with 1 additions and 28 deletions

View File

@ -53,8 +53,6 @@ bool OriginAttributes::CopyFromLoadContext(nsILoadContext* aLoadContext)
void
OriginAttributes::CreateSuffix(nsACString& aStr) const
{
MOZ_RELEASE_ASSERT(mAppId != nsIScriptSecurityManager::UNKNOWN_APP_ID);
UniquePtr<URLParams> params(new URLParams());
nsAutoString value;
@ -127,10 +125,6 @@ public:
return false;
}
if (mOriginAttributes->mAppId == nsIScriptSecurityManager::UNKNOWN_APP_ID) {
return false;
}
return true;
}
@ -222,14 +216,6 @@ BasePrincipal::GetOrigin(nsACString& aOrigin)
nsresult rv = GetOriginInternal(aOrigin);
NS_ENSURE_SUCCESS(rv, rv);
// OriginAttributes::CreateSuffix asserts against UNKNOWN_APP_ID. It's trivial
// to trigger this getter from script on such a principal, so we handle it
// here at the API entry point.
if (mOriginAttributes.mAppId == nsIScriptSecurityManager::UNKNOWN_APP_ID) {
NS_WARNING("Refusing to provide canonical origin string to principal with UNKNOWN_APP_ID");
return NS_ERROR_FAILURE;
}
nsAutoCString suffix;
mOriginAttributes.CreateSuffix(suffix);
aOrigin.Append(suffix);
@ -325,8 +311,6 @@ BasePrincipal::GetIsNullPrincipal(bool* aIsNullPrincipal)
NS_IMETHODIMP
BasePrincipal::GetJarPrefix(nsACString& aJarPrefix)
{
MOZ_ASSERT(AppId() != nsIScriptSecurityManager::UNKNOWN_APP_ID);
mozilla::GetJarPrefix(mOriginAttributes.mAppId, mOriginAttributes.mInBrowser, aJarPrefix);
return NS_OK;
}

View File

@ -57,7 +57,6 @@ nsresult
nsNullPrincipal::Init(const OriginAttributes& aOriginAttributes)
{
mOriginAttributes = aOriginAttributes;
MOZ_ASSERT(AppId() != nsIScriptSecurityManager::UNKNOWN_APP_ID);
mURI = nsNullPrincipalURI::Create();
NS_ENSURE_TRUE(mURI, NS_ERROR_NOT_AVAILABLE);
@ -173,9 +172,6 @@ nsNullPrincipal::Read(nsIObjectInputStream* aStream)
NS_IMETHODIMP
nsNullPrincipal::Write(nsIObjectOutputStream* aStream)
{
NS_ENSURE_TRUE(mOriginAttributes.mAppId != nsIScriptSecurityManager::UNKNOWN_APP_ID,
NS_ERROR_INVALID_ARG);
nsAutoCString suffix;
OriginAttributesRef().CreateSuffix(suffix);

View File

@ -427,9 +427,6 @@ NS_IMETHODIMP
nsPrincipal::Write(nsIObjectOutputStream* aStream)
{
NS_ENSURE_STATE(mCodebase);
NS_ENSURE_TRUE(mOriginAttributes.mAppId != nsIScriptSecurityManager::UNKNOWN_APP_ID,
NS_ERROR_INVALID_ARG);
nsresult rv = NS_WriteOptionalCompoundObject(aStream, mCodebase, NS_GET_IID(nsIURI),
true);
if (NS_FAILED(rv)) {

View File

@ -98,11 +98,7 @@ function run_test() {
checkOriginAttributes(exampleOrg_addon, { addonId: "dummy" }, '^addonId=dummy');
do_check_eq(exampleOrg_addon.origin, 'http://example.org^addonId=dummy');
// Make sure that we refuse to create .origin for principals with UNKNOWN_APP_ID.
var simplePrin = ssm.getSimpleCodebasePrincipal(makeURI('http://example.com'));
try { simplePrin.origin; do_check_true(false); } catch (e) { do_check_true(true); }
// Make sure we don't crash when serializing them either.
// Make sure we don't crash when serializing principals with UNKNOWN_APP_ID.
try {
let binaryStream = Cc["@mozilla.org/binaryoutputstream;1"].
createInstance(Ci.nsIObjectOutputStream);