Bug 1341218 - nsNullPrincipal should serialize its URL, r=qdot

This commit is contained in:
Andrea Marchesini 2017-02-23 14:30:23 +01:00
Родитель d637db915a
Коммит d0b50071c8
3 изменённых файлов: 31 добавлений и 11 удалений

Просмотреть файл

@ -166,25 +166,43 @@ nsNullPrincipal::Read(nsIObjectInputStream* aStream)
// that the Init() method has already been invoked by the time we deserialize.
// This is in contrast to nsPrincipal, which uses NS_GENERIC_FACTORY_CONSTRUCTOR,
// in which case ::Read needs to invoke Init().
nsAutoCString suffix;
nsresult rv = aStream->ReadCString(suffix);
nsAutoCString spec;
nsresult rv = aStream->ReadCString(spec);
NS_ENSURE_SUCCESS(rv, rv);
bool ok = mOriginAttributes.PopulateFromSuffix(suffix);
nsCOMPtr<nsIURI> uri;
rv = NS_NewURI(getter_AddRefs(uri), spec);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoCString suffix;
rv = aStream->ReadCString(suffix);
NS_ENSURE_SUCCESS(rv, rv);
OriginAttributes attrs;
bool ok = attrs.PopulateFromSuffix(suffix);
NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
return NS_OK;
return Init(attrs, uri);
}
NS_IMETHODIMP
nsNullPrincipal::Write(nsIObjectOutputStream* aStream)
{
NS_ENSURE_STATE(mURI);
nsAutoCString spec;
nsresult rv = mURI->GetSpec(spec);
NS_ENSURE_SUCCESS(rv, rv);
rv = aStream->WriteStringZ(spec.get());
NS_ENSURE_SUCCESS(rv, rv);
nsAutoCString suffix;
OriginAttributesRef().CreateSuffix(suffix);
nsresult rv = aStream->WriteStringZ(suffix.get());
rv = aStream->WriteStringZ(suffix.get());
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}

Просмотреть файл

@ -512,10 +512,11 @@ nsContentUtils::Init()
sSecurityManager->GetSystemPrincipal(&sSystemPrincipal);
MOZ_ASSERT(sSystemPrincipal);
// We use the constructor here because we want infallible initialization; we
// apparently don't care whether sNullSubjectPrincipal has a sane URI or not.
RefPtr<nsNullPrincipal> nullPrincipal = new nsNullPrincipal();
nullPrincipal->Init();
RefPtr<nsNullPrincipal> nullPrincipal = nsNullPrincipal::Create();
if (!nullPrincipal) {
return NS_ERROR_FAILURE;
}
nullPrincipal.forget(&sNullSubjectPrincipal);
nsresult rv = CallGetService(NS_IOSERVICE_CONTRACTID, &sIOService);

Просмотреть файл

@ -104,6 +104,7 @@
#include "nsIScriptSecurityManager.h"
#include "nsIPermissionManager.h"
#include "nsIPrincipal.h"
#include "nsNullPrincipal.h"
#include "nsIDOMWindow.h"
#include "nsPIDOMWindow.h"
@ -2738,7 +2739,7 @@ nsDocument::InitCSP(nsIChannel* aChannel)
if (cspSandboxFlags & SANDBOXED_ORIGIN) {
// If the new CSP sandbox flags do not have the allow-same-origin flag
// reset the document principal to a null principal
principal = do_CreateInstance("@mozilla.org/nullprincipal;1");
principal = nsNullPrincipal::Create();
SetPrincipal(principal);
}