Bug 948574 - Provide limited access to nsISiteSecurityService apis in the child, and prevent the direct creation of nsISiteSecurityService. r=bz, sr=ptheriault, original author: David Keeler <dkeeler@mozilla.com>

This commit is contained in:
Jim Mathies 2014-07-22 07:17:45 -05:00
Родитель 1354fd692a
Коммит e5f4ec183a
5 изменённых файлов: 48 добавлений и 9 удалений

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

@ -22,6 +22,7 @@
#include "mozilla/Telemetry.h"
#include "mozilla/unused.h"
#include "mozilla/VisualEventTracer.h"
#include "URIUtils.h"
#ifdef MOZ_LOGGING
// so we can get logging even in release builds (but only for some things)
@ -4559,16 +4560,24 @@ nsDocShell::DisplayLoadError(nsresult aError, nsIURI *aURI,
// if this is a Strict-Transport-Security host and the cert
// is bad, don't allow overrides (STS Spec section 7.3).
nsCOMPtr<nsISiteSecurityService> sss =
do_GetService(NS_SSSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
uint32_t flags =
mInPrivateBrowsing ? nsISocketProvider::NO_PERMANENT_STORAGE : 0;
uint32_t type = nsISiteSecurityService::HEADER_HSTS;
uint32_t flags = mInPrivateBrowsing
? nsISocketProvider::NO_PERMANENT_STORAGE
: 0;
bool isStsHost = false;
rv = sss->IsSecureURI(nsISiteSecurityService::HEADER_HSTS,
aURI, flags, &isStsHost);
NS_ENSURE_SUCCESS(rv, rv);
if (XRE_GetProcessType() == GeckoProcessType_Default) {
nsCOMPtr<nsISiteSecurityService> sss =
do_GetService(NS_SSSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = sss->IsSecureURI(type, aURI, flags, &isStsHost);
NS_ENSURE_SUCCESS(rv, rv);
} else {
mozilla::dom::ContentChild* cc =
mozilla::dom::ContentChild::GetSingleton();
mozilla::ipc::URIParams uri;
SerializeURI(aURI, uri);
cc->SendIsSecureURI(type, uri, flags, &isStsHost);
}
uint32_t bucketId;
if (isStsHost) {

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

@ -98,6 +98,7 @@
#include "nsIPresShell.h"
#include "nsIRemoteBlob.h"
#include "nsIScriptError.h"
#include "nsISiteSecurityService.h"
#include "nsIStyleSheet.h"
#include "nsISupportsPrimitives.h"
#include "nsIURIFixup.h"
@ -3239,6 +3240,23 @@ ContentParent::RecvGetSystemMemory(const uint64_t& aGetterId)
return true;
}
bool
ContentParent::RecvIsSecureURI(const uint32_t& type,
const URIParams& uri,
const uint32_t& flags,
bool* isSecureURI)
{
nsCOMPtr<nsISiteSecurityService> sss(do_GetService(NS_SSSERVICE_CONTRACTID));
if (!sss) {
return false;
}
nsCOMPtr<nsIURI> ourURI = DeserializeURI(uri);
if (!ourURI) {
return false;
}
nsresult rv = sss->IsSecureURI(type, ourURI, flags, isSecureURI);
return NS_SUCCEEDED(rv);
}
bool
ContentParent::RecvLoadURIExternal(const URIParams& uri)

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

@ -422,6 +422,9 @@ private:
virtual bool RecvGetRandomValues(const uint32_t& length,
InfallibleTArray<uint8_t>* randomValues) MOZ_OVERRIDE;
virtual bool RecvIsSecureURI(const uint32_t& type, const URIParams& uri,
const uint32_t& flags, bool* isSecureURI);
virtual bool DeallocPHalParent(PHalParent*) MOZ_OVERRIDE;
virtual bool DeallocPIndexedDBParent(PIndexedDBParent* aActor) MOZ_OVERRIDE;

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

@ -478,6 +478,9 @@ parent:
async GetSystemMemory(uint64_t getterId);
sync IsSecureURI(uint32_t type, URIParams uri, uint32_t flags)
returns (bool isSecureURI);
PHal();
PIndexedDB();

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

@ -20,6 +20,7 @@
#include "mozilla/Preferences.h"
#include "mozilla/LinkedList.h"
#include "nsSecurityHeaderParser.h"
#include "nsXULAppAPI.h"
// A note about the preload list:
// When a site specifically disables sts by sending a header with
@ -87,6 +88,11 @@ NS_IMPL_ISUPPORTS(nsSiteSecurityService,
nsresult
nsSiteSecurityService::Init()
{
// Child processes are not allowed direct access to this.
if (XRE_GetProcessType() != GeckoProcessType_Default) {
MOZ_CRASH("Child process: no direct access to nsSiteSecurityService");
}
nsresult rv;
mPermMgr = do_GetService(NS_PERMISSIONMANAGER_CONTRACTID, &rv);