Bug 1474812 - No needs to store granted storage access in nsILoadInfo and in the inner window, r=ehsan

This commit is contained in:
Andrea Marchesini 2018-07-13 12:02:19 +02:00
Родитель aab81fd480
Коммит 1498612e1b
21 изменённых файлов: 437 добавлений и 463 удалений

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

@ -29,6 +29,7 @@
#include "gfxPrefs.h"
#include "ImageOps.h"
#include "mozAutoDocUpdate.h"
#include "mozilla/AntiTrackingCommon.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/Attributes.h"
#include "mozilla/AutoRestore.h"
@ -8870,21 +8871,10 @@ nsContentUtils::StorageDisabledByAntiTracking(nsPIDOMWindowInner* aWindow,
}
if (aWindow) {
nsCOMPtr<nsIHttpChannel> httpChannel;
nsIDocument* document = aWindow->GetExtantDoc();
if (document) {
httpChannel = do_QueryInterface(document->GetChannel());
}
// If this is not a tracking resource, nothing is disabled.
if (!httpChannel || !httpChannel->GetIsTrackingResource()) {
return false;
}
// Maybe we want to grant this origin.
nsIURI* documentURI = aURI ? aURI : aWindow->GetDocumentURI();
if (documentURI &&
nsGlobalWindowInner::Cast(aWindow)->IsFirstPartyStorageAccessGrantedFor(documentURI)) {
AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(aWindow,
documentURI)) {
return false;
}
@ -8910,13 +8900,8 @@ nsContentUtils::StorageDisabledByAntiTracking(nsPIDOMWindowInner* aWindow,
return false;
}
nsCOMPtr<nsILoadInfo> loadInfo;
rv = aChannel->GetLoadInfo(getter_AddRefs(loadInfo));
if (NS_WARN_IF(NS_FAILED(rv))) {
return false;
}
return !loadInfo->IsFirstPartyStorageAccessGrantedFor(uri);
return AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(httpChannel,
uri);
}
// static, private

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

@ -12,6 +12,7 @@
#include "nsDocument.h"
#include "nsIDocumentInlines.h"
#include "mozilla/AnimationComparator.h"
#include "mozilla/AntiTrackingCommon.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/AutoRestore.h"
#include "mozilla/BinarySearch.h"
@ -12454,7 +12455,8 @@ nsIDocument::MaybeAllowStorageForOpener()
return;
}
nsGlobalWindowInner::Cast(openerInner)->AddFirstPartyStorageAccessGrantedFor(origin);
AntiTrackingCommon::AddFirstPartyStorageAccessGrantedFor(origin,
openerInner);
}
bool

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

@ -36,7 +36,6 @@
#if defined(MOZ_WIDGET_ANDROID)
#include "mozilla/dom/WindowOrientationObserver.h"
#endif
#include "mozilla/StaticPrefs.h"
#include "nsDOMOfflineResourceList.h"
#include "nsError.h"
#include "nsIIdleService.h"
@ -334,10 +333,6 @@ using mozilla::dom::cache::CacheStorage;
// Min idle notification time in seconds.
#define MIN_IDLE_NOTIFICATION_TIME_S 1
// Anti-tracking permission expiration
#define ANTITRACKING_EXPIRATION 2592000000 // 30 days.
#define ANTITRACKING_PERM_KEY "3rdPartyStorage"
static LazyLogModule gDOMLeakPRLogInner("DOMLeakInner");
static bool gIdleObserversAPIFuzzTimeDisabled = false;
@ -922,8 +917,7 @@ nsGlobalWindowInner::nsGlobalWindowInner(nsGlobalWindowOuter *aOuterWindow)
mObservingDidRefresh(false),
mIteratingDocumentFlushedResolvers(false),
mCanSkipCCGeneration(0),
mBeforeUnloadListenerCount(0),
mStorageGrantedOriginPopulated(false)
mBeforeUnloadListenerCount(0)
{
mIsInnerWindow = true;
@ -1241,7 +1235,6 @@ nsGlobalWindowInner::FreeInnerObjects()
}
UnlinkHostObjectURIs();
ReleaseFirstPartyStorageAccessGrantedOrigins();
NotifyWindowIDDestroyed("inner-window-destroyed");
@ -1565,7 +1558,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindowInner)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mIntlUtils)
tmp->UnlinkHostObjectURIs();
tmp->ReleaseFirstPartyStorageAccessGrantedOrigins();
NS_IMPL_CYCLE_COLLECTION_UNLINK(mIdleRequestExecutor)
@ -8062,289 +8054,6 @@ nsGlobalWindowInner::GetRegionalPrefsLocales(nsTArray<nsString>& aLocales)
}
}
void
nsGlobalWindowInner::AddFirstPartyStorageAccessGrantedFor(const nsAString& aOrigin,
bool aOverwritten)
{
MOZ_ASSERT(StaticPrefs::privacy_restrict3rdpartystorage_enabled());
if (aOverwritten) {
SaveFirstPartyStorageAccessGrantedFor(aOrigin);
}
for (StorageGrantedOrigin& data : mStorageGrantedOrigins) {
if (data.mOrigin == aOrigin) {
data.mOverwritten = aOverwritten;
return;
}
}
bool wasAllowed =
nsContentUtils::StorageDisabledByAntiTracking(this, nullptr, nullptr);
StorageGrantedOrigin* data = mStorageGrantedOrigins.AppendElement();
data->mOrigin = aOrigin;
data->mOverwritten = aOverwritten;
if (!wasAllowed &&
nsContentUtils::StorageDisabledByAntiTracking(this, nullptr, nullptr)) {
PropagateFirstPartyStorageAccessGrantedToWorkers(this);
}
// Let's store the origin in the loadInfo as well.
if (mDoc) {
nsCOMPtr<nsIChannel> channel = mDoc->GetChannel();
if (channel) {
nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
if (loadInfo) {
loadInfo->AddFirstPartyStorageAccessGrantedFor(aOrigin);
}
}
}
}
void
nsGlobalWindowInner::GetFirstPartyStorageAccessGrantedOrigins(nsTArray<nsString>& aOrigin)
{
aOrigin.Clear();
if (!StaticPrefs::privacy_restrict3rdpartystorage_enabled()) {
return;
}
MaybeRestoreFirstPartyStorageAccessGrantedOrigins();
for (const StorageGrantedOrigin& data : mStorageGrantedOrigins) {
aOrigin.AppendElement(data.mOrigin);
}
}
bool
nsGlobalWindowInner::IsFirstPartyStorageAccessGrantedFor(nsIURI* aURI)
{
MOZ_ASSERT(aURI);
if (!StaticPrefs::privacy_restrict3rdpartystorage_enabled()) {
return true;
}
MaybeRestoreFirstPartyStorageAccessGrantedOrigins();
if (mStorageGrantedOrigins.IsEmpty()) {
return false;
}
nsAutoString origin;
nsresult rv = nsContentUtils::GetUTFOrigin(aURI, origin);
if (NS_WARN_IF(NS_FAILED(rv))) {
return false;
}
for (const StorageGrantedOrigin& data : mStorageGrantedOrigins) {
if (data.mOrigin.Equals(origin)) {
return true;
}
}
return false;
}
void
nsGlobalWindowInner::ReleaseFirstPartyStorageAccessGrantedOrigins()
{
mStorageGrantedOriginPopulated = false;
mStorageGrantedOrigins.Clear();
}
namespace mozilla {
namespace dom {
extern void
SendFirstPartyStorageAccessGrantedForOriginToParentProcess(nsIPrincipal* aPrincipal,
const nsACString& aParentOrigin,
const nsACString& aGrantedOrigin);
} // namespace dom
} // namespace mozilla
void
nsGlobalWindowInner::SaveFirstPartyStorageAccessGrantedFor(const nsAString& aOrigin)
{
MOZ_ASSERT(StaticPrefs::privacy_restrict3rdpartystorage_enabled());
// Now we need the principal and the origin of the parent window.
nsIPrincipal* parentPrincipal = GetTopLevelStorageAreaPrincipal();
if (NS_WARN_IF(!parentPrincipal)) {
return;
}
nsAutoCString parentOrigin;
nsresult rv = parentPrincipal->GetOriginNoSuffix(parentOrigin);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
// Let's take the principal and the origin of the current window.
nsIPrincipal* principal = GetPrincipal();
if (NS_WARN_IF(!principal)) {
return;
}
NS_ConvertUTF16toUTF8 grantedOrigin(aOrigin);
if (XRE_IsParentProcess()) {
SaveFirstPartyStorageAccessGrantedForOriginOnParentProcess(principal,
parentOrigin,
grantedOrigin);
return;
}
// We have this external function because ContentChild includes windows.h and
// for this reason it cannot be included here.
SendFirstPartyStorageAccessGrantedForOriginToParentProcess(principal,
parentOrigin,
grantedOrigin);
}
/* static */ void
nsGlobalWindowInner::SaveFirstPartyStorageAccessGrantedForOriginOnParentProcess(nsIPrincipal* aPrincipal,
const nsCString& aParentOrigin,
const nsCString& aGrantedOrigin)
{
MOZ_ASSERT(XRE_IsParentProcess());
if (NS_WARN_IF(!aPrincipal)) {
// The child process is sending something wrong. Let's ignore it.
return;
}
nsAutoCString origin;
nsresult rv = aPrincipal->GetOriginNoSuffix(origin);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
nsCOMPtr<nsIPermissionManager> pm = services::GetPermissionManager();
if (NS_WARN_IF(!pm)) {
return;
}
int64_t when = (PR_Now() / PR_USEC_PER_MSEC) + ANTITRACKING_EXPIRATION;
// We store a permission for the 3rd party principal, to know that we grant
// the storage permission when loaded by the current parent origin.
nsAutoCString type;
if (origin == aGrantedOrigin) {
type = nsPrintfCString(ANTITRACKING_PERM_KEY "^%s", aParentOrigin.get());
} else {
type = nsPrintfCString(ANTITRACKING_PERM_KEY "^%s^%s", aParentOrigin.get(),
aGrantedOrigin.get());
}
rv = pm->AddFromPrincipal(aPrincipal, type.get(),
nsIPermissionManager::ALLOW_ACTION,
nsIPermissionManager::EXPIRE_TIME, when);
Unused << NS_WARN_IF(NS_FAILED(rv));
}
void
nsGlobalWindowInner::MaybeRestoreFirstPartyStorageAccessGrantedOrigins()
{
if (!StaticPrefs::privacy_restrict3rdpartystorage_enabled()) {
return;
}
if (mStorageGrantedOriginPopulated) {
return;
}
mStorageGrantedOriginPopulated = true;
// Now we need the principal and the origin of the parent window.
nsIPrincipal* parentPrincipal = GetTopLevelStorageAreaPrincipal();
if (!parentPrincipal) {
// No parent window.
return;
}
nsAutoCString parentOrigin;
nsresult rv = parentPrincipal->GetOriginNoSuffix(parentOrigin);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
// Let's take the principal and the origin of the current window.
nsIPrincipal* principal = GetPrincipal();
if (NS_WARN_IF(!principal)) {
return;
}
nsAutoCString origin;
rv = principal->GetOriginNoSuffix(origin);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
nsCOMPtr<nsIPermissionManager> pm = services::GetPermissionManager();
if (NS_WARN_IF(!pm)) {
return;
}
nsCOMPtr<nsISimpleEnumerator> enumerator;
rv = pm->GetAllForPrincipal(principal, getter_AddRefs(enumerator));
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
bool more = false;
nsCOMPtr<nsISupports> iter;
nsCOMPtr<nsIPermission> perm;
while (NS_SUCCEEDED(enumerator->HasMoreElements(&more)) && more) {
rv = enumerator->GetNext(getter_AddRefs(iter));
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
perm = do_QueryInterface(iter);
if (NS_WARN_IF(!perm)) {
return;
}
nsAutoCString type;
rv = perm->GetType(type);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
if (!StringBeginsWith(type, NS_LITERAL_CSTRING(ANTITRACKING_PERM_KEY "^"))) {
continue;
}
nsCCharSeparatedTokenizer token(type, '^');
MOZ_ASSERT(token.hasMoreTokens());
auto value = token.nextToken();
MOZ_ASSERT(value.EqualsLiteral(ANTITRACKING_PERM_KEY));
nsAutoCString originA;
if (token.hasMoreTokens()) {
originA = token.nextToken();
}
// This permission was granted for another top-level window.
if (originA != parentOrigin) {
continue;
}
nsAutoCString originB;
if (token.hasMoreTokens()) {
originB = token.nextToken();
}
AddFirstPartyStorageAccessGrantedFor(NS_ConvertUTF8toUTF16(originB.IsEmpty() ? origin : originB),
false /* no overwrite */);
}
}
IntlUtils*
nsGlobalWindowInner::GetIntlUtils(ErrorResult& aError)
{

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

@ -717,20 +717,6 @@ public:
mozilla::dom::IntlUtils*
GetIntlUtils(mozilla::ErrorResult& aRv);
void
AddFirstPartyStorageAccessGrantedFor(const nsAString& aOrigin, bool aOverwritten = true);
void
GetFirstPartyStorageAccessGrantedOrigins(nsTArray<nsString>& aOrigins);
bool
IsFirstPartyStorageAccessGrantedFor(nsIURI* aURI);
static void
SaveFirstPartyStorageAccessGrantedForOriginOnParentProcess(nsIPrincipal* aPrincipal,
const nsCString& aParentOrigin,
const nsCString& aGrantedOrigin);
public:
void Alert(nsIPrincipal& aSubjectPrincipal,
mozilla::ErrorResult& aError);
@ -1073,15 +1059,6 @@ protected:
mozilla::dom::CallerType aCallerType,
mozilla::ErrorResult& aError);
void
ReleaseFirstPartyStorageAccessGrantedOrigins();
void
SaveFirstPartyStorageAccessGrantedFor(const nsAString& aOrigin);
void
MaybeRestoreFirstPartyStorageAccessGrantedOrigins();
// Array of idle observers that are notified of idle events.
nsTObserverArray<IdleObserverHolder> mIdleObservers;
@ -1129,9 +1106,6 @@ protected:
// Get the parent, returns null if this is a toplevel window
nsPIDOMWindowOuter* GetParentInternal();
// Get the parent principal, returns null if this is a toplevel window.
nsIPrincipal* GetTopLevelStorageAreaPrincipal();
public:
// popup tracking
bool IsPopupSpamWindow();
@ -1249,6 +1223,9 @@ public:
public:
virtual already_AddRefed<nsPIWindowRoot> GetTopWindowRoot() override;
// Get the parent principal, returns null if this is a toplevel window.
nsIPrincipal* GetTopLevelStorageAreaPrincipal();
protected:
static void NotifyDOMWindowDestroyed(nsGlobalWindowInner* aWindow);
void NotifyWindowIDDestroyed(const char* aTopic);
@ -1502,13 +1479,6 @@ protected:
nsTArray<mozilla::UniquePtr<PromiseDocumentFlushedResolver>> mDocumentFlushedResolvers;
struct StorageGrantedOrigin {
nsString mOrigin;
bool mOverwritten;
};
nsTArray<StorageGrantedOrigin> mStorageGrantedOrigins;
bool mStorageGrantedOriginPopulated;
static InnerWindowByIdTable* sInnerWindowsById;
// Members in the mChromeFields member should only be used in chrome windows.

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

@ -17,6 +17,7 @@
#include "nsHistory.h"
#include "nsDOMNavigationTiming.h"
#include "nsIDOMStorageManager.h"
#include "mozilla/AntiTrackingCommon.h"
#include "mozilla/dom/EventTarget.h"
#include "mozilla/dom/LocalStorage.h"
#include "mozilla/dom/Storage.h"
@ -7078,7 +7079,7 @@ nsGlobalWindowOuter::MaybeAllowStorageForOpenedWindow(nsIURI* aURI)
return;
}
inner->AddFirstPartyStorageAccessGrantedFor(origin, true);
AntiTrackingCommon::AddFirstPartyStorageAccessGrantedFor(origin, inner);
}
//*****************************************************************************

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

@ -3306,25 +3306,6 @@ NextWindowID()
return (processBits << kWindowIDWindowBits) | windowBits;
}
// This code goes here rather than nsGlobalWindow.cpp because nsGlobalWindow.cpp
// can't include ContentChild.h since it includes windows.h.
void
SendFirstPartyStorageAccessGrantedForOriginToParentProcess(nsIPrincipal* aPrincipal,
const nsACString& aParentOrigin,
const nsACString& aGrantedOrigin)
{
MOZ_ASSERT(!XRE_IsParentProcess());
ContentChild* cc = ContentChild::GetSingleton();
MOZ_ASSERT(cc);
// This is not really secure, because here we have the content process sending
// the request of storing a permission.
Unused << cc->SendFirstPartyStorageAccessGrantedForOrigin(IPC::Principal(aPrincipal),
nsCString(aParentOrigin),
nsCString(aGrantedOrigin));
}
mozilla::ipc::IPCResult
ContentChild::RecvInvokeDragSession(nsTArray<IPCDataTransfer>&& aTransfers,
const uint32_t& aAction)

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

@ -863,11 +863,6 @@ private:
uint64_t
NextWindowID();
void
SendFirstPartyStorageAccessGrantedForOriginToParentProcess(nsIPrincipal* aPrincipal,
const nsACString& aParentOrigin,
const nsACString& aGrantedOrigin);
} // namespace dom
} // namespace mozilla

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

@ -29,6 +29,7 @@
#include "mozilla/a11y/AccessibleWrap.h"
#include "mozilla/a11y/Compatibility.h"
#endif
#include "mozilla/AntiTrackingCommon.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/StyleSheetInlines.h"
@ -117,7 +118,6 @@
#include "nsDebugImpl.h"
#include "nsFrameLoader.h"
#include "nsFrameMessageManager.h"
#include "nsGlobalWindowInner.h"
#include "nsHashPropertyBag.h"
#include "nsIAlertsService.h"
#include "nsIClipboard.h"
@ -5760,12 +5760,12 @@ ContentParent::RecvBHRThreadHang(const HangDetails& aDetails)
}
mozilla::ipc::IPCResult
ContentParent::RecvFirstPartyStorageAccessGrantedForOrigin(const Principal& aPrincipal,
const nsCString& aParentOrigin,
ContentParent::RecvFirstPartyStorageAccessGrantedForOrigin(const Principal& aParentPrincipal,
const nsCString& aTrackingOrigin,
const nsCString& aGrantedOrigin)
{
nsGlobalWindowInner::SaveFirstPartyStorageAccessGrantedForOriginOnParentProcess(aPrincipal,
aParentOrigin,
aGrantedOrigin);
AntiTrackingCommon::SaveFirstPartyStorageAccessGrantedForOriginOnParentProcess(aParentPrincipal,
aTrackingOrigin,
aGrantedOrigin);
return IPC_OK();
}

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

@ -1225,8 +1225,8 @@ public:
const HangDetails& aHangDetails) override;
virtual mozilla::ipc::IPCResult
RecvFirstPartyStorageAccessGrantedForOrigin(const Principal& aPrincipal,
const nsCString& aParentOrigin,
RecvFirstPartyStorageAccessGrantedForOrigin(const Principal& aParentPrincipal,
const nsCString& aTrackingOrigin,
const nsCString& aGrantedOrigin) override;
// Notify the ContentChild to enable the input event prioritization when

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

@ -1160,11 +1160,11 @@ parent:
async AddPerformanceMetrics(nsID aID, PerformanceInfo[] aMetrics);
/*
* A 3rd party context (aPrincipal) has received the permission granted to
* have access to aGrantedOrigin when loaded by aParentOrigin.
* A 3rd party tracking origin (aTrackingOrigin) has received the permission
* granted to have access to aGrantedOrigin when loaded by aParentPrincipal.
*/
async FirstPartyStorageAccessGrantedForOrigin(Principal aPrincipal,
nsCString aParentOrigin,
async FirstPartyStorageAccessGrantedForOrigin(Principal aParentPrincipal,
nsCString aTrackingOrigin,
nsCString aGrantedOrigin);
both:

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

@ -339,6 +339,15 @@ LoadInfoToLoadInfoArgs(nsILoadInfo *aLoadInfo,
sandboxedLoadingPrincipalInfo = sandboxedLoadingPrincipalInfoTemp;
}
OptionalPrincipalInfo topLevelStorageAreaPrincipalInfo = mozilla::void_t();
if (aLoadInfo->TopLevelStorageAreaPrincipal()) {
PrincipalInfo topLevelStorageAreaPrincipalInfoTemp;
rv = PrincipalToPrincipalInfo(aLoadInfo->TopLevelStorageAreaPrincipal(),
&topLevelStorageAreaPrincipalInfoTemp);
NS_ENSURE_SUCCESS(rv, rv);
topLevelStorageAreaPrincipalInfo = topLevelStorageAreaPrincipalInfoTemp;
}
OptionalURIParams optionalResultPrincipalURI = mozilla::void_t();
nsCOMPtr<nsIURI> resultPrincipalURI;
Unused << aLoadInfo->GetResultPrincipalURI(getter_AddRefs(resultPrincipalURI));
@ -399,11 +408,11 @@ LoadInfoToLoadInfoArgs(nsILoadInfo *aLoadInfo,
triggeringPrincipalInfo,
principalToInheritInfo,
sandboxedLoadingPrincipalInfo,
topLevelStorageAreaPrincipalInfo,
optionalResultPrincipalURI,
aLoadInfo->GetSecurityFlags(),
aLoadInfo->InternalContentPolicyType(),
static_cast<uint32_t>(aLoadInfo->GetTainting()),
aLoadInfo->GetFirstPartyStorageAccessGrantedOrigins(),
aLoadInfo->GetUpgradeInsecureRequests(),
aLoadInfo->GetBrowserUpgradeInsecureRequests(),
aLoadInfo->GetBrowserWouldUpgradeInsecureRequests(),
@ -478,6 +487,13 @@ LoadInfoArgsToLoadInfo(const OptionalLoadInfoArgs& aOptionalLoadInfoArgs,
NS_ENSURE_SUCCESS(rv, rv);
}
nsCOMPtr<nsIPrincipal> topLevelStorageAreaPrincipal;
if (loadInfoArgs.topLevelStorageAreaPrincipalInfo().type() != OptionalPrincipalInfo::Tvoid_t) {
topLevelStorageAreaPrincipal =
PrincipalInfoToPrincipal(loadInfoArgs.topLevelStorageAreaPrincipalInfo(), &rv);
NS_ENSURE_SUCCESS(rv, rv);
}
nsCOMPtr<nsIURI> resultPrincipalURI;
if (loadInfoArgs.resultPrincipalURI().type() != OptionalURIParams::Tvoid_t) {
resultPrincipalURI = DeserializeURI(loadInfoArgs.resultPrincipalURI());
@ -544,6 +560,7 @@ LoadInfoArgsToLoadInfo(const OptionalLoadInfoArgs& aOptionalLoadInfoArgs,
triggeringPrincipal,
principalToInherit,
sandboxedLoadingPrincipal,
topLevelStorageAreaPrincipal,
resultPrincipalURI,
clientInfo,
reservedClientInfo,
@ -552,7 +569,6 @@ LoadInfoArgsToLoadInfo(const OptionalLoadInfoArgs& aOptionalLoadInfoArgs,
loadInfoArgs.securityFlags(),
loadInfoArgs.contentPolicyType(),
static_cast<LoadTainting>(loadInfoArgs.tainting()),
loadInfoArgs.firstPartyStorageAccessGrantedOrigins(),
loadInfoArgs.upgradeInsecureRequests(),
loadInfoArgs.browserUpgradeInsecureRequests(),
loadInfoArgs.browserWouldUpgradeInsecureRequests(),

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

@ -154,7 +154,8 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal,
nsGlobalWindowInner* innerWindow =
nsGlobalWindowInner::Cast(contextOuter->GetCurrentInnerWindow());
if (innerWindow) {
innerWindow->GetFirstPartyStorageAccessGrantedOrigins(mFirstPartyStorageAccessGrantedOrigins);
mTopLevelStorageAreaPrincipal =
innerWindow->GetTopLevelStorageAreaPrincipal();
}
}
@ -343,7 +344,8 @@ LoadInfo::LoadInfo(nsPIDOMWindowOuter* aOuterWindow,
nsGlobalWindowInner* innerWindow =
nsGlobalWindowInner::Cast(aOuterWindow->GetCurrentInnerWindow());
if (innerWindow) {
innerWindow->GetFirstPartyStorageAccessGrantedOrigins(mFirstPartyStorageAccessGrantedOrigins);
mTopLevelStorageAreaPrincipal =
innerWindow->GetTopLevelStorageAreaPrincipal();
}
// get the docshell from the outerwindow, and then get the originattributes
@ -367,6 +369,7 @@ LoadInfo::LoadInfo(const LoadInfo& rhs)
, mTriggeringPrincipal(rhs.mTriggeringPrincipal)
, mPrincipalToInherit(rhs.mPrincipalToInherit)
, mSandboxedLoadingPrincipal(rhs.mSandboxedLoadingPrincipal)
, mTopLevelStorageAreaPrincipal(rhs.mTopLevelStorageAreaPrincipal)
, mResultPrincipalURI(rhs.mResultPrincipalURI)
, mClientInfo(rhs.mClientInfo)
// mReservedClientSource must be handled specially during redirect
@ -417,6 +420,7 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal,
nsIPrincipal* aTriggeringPrincipal,
nsIPrincipal* aPrincipalToInherit,
nsIPrincipal* aSandboxedLoadingPrincipal,
nsIPrincipal* aTopLevelStorageAreaPrincipal,
nsIURI* aResultPrincipalURI,
const Maybe<ClientInfo>& aClientInfo,
const Maybe<ClientInfo>& aReservedClientInfo,
@ -425,7 +429,6 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal,
nsSecurityFlags aSecurityFlags,
nsContentPolicyType aContentPolicyType,
LoadTainting aTainting,
const nsTArray<nsString>& aFirstPartyStorageAccessGrantedOrigins,
bool aUpgradeInsecureRequests,
bool aBrowserUpgradeInsecureRequests,
bool aBrowserWouldUpgradeInsecureRequests,
@ -457,6 +460,7 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal,
: mLoadingPrincipal(aLoadingPrincipal)
, mTriggeringPrincipal(aTriggeringPrincipal)
, mPrincipalToInherit(aPrincipalToInherit)
, mTopLevelStorageAreaPrincipal(aTopLevelStorageAreaPrincipal)
, mResultPrincipalURI(aResultPrincipalURI)
, mClientInfo(aClientInfo)
, mReservedClientInfo(aReservedClientInfo)
@ -465,7 +469,6 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal,
, mSecurityFlags(aSecurityFlags)
, mInternalContentPolicyType(aContentPolicyType)
, mTainting(aTainting)
, mFirstPartyStorageAccessGrantedOrigins(aFirstPartyStorageAccessGrantedOrigins)
, mUpgradeInsecureRequests(aUpgradeInsecureRequests)
, mBrowserUpgradeInsecureRequests(aBrowserUpgradeInsecureRequests)
, mBrowserWouldUpgradeInsecureRequests(aBrowserWouldUpgradeInsecureRequests)
@ -639,6 +642,19 @@ LoadInfo::GetSandboxedLoadingPrincipal(nsIPrincipal** aPrincipal)
return NS_OK;
}
NS_IMETHODIMP
LoadInfo::GetTopLevelStorageAreaPrincipal(nsIPrincipal** aTopLevelStorageAreaPrincipal)
{
NS_IF_ADDREF(*aTopLevelStorageAreaPrincipal = mTopLevelStorageAreaPrincipal);
return NS_OK;
}
nsIPrincipal*
LoadInfo::TopLevelStorageAreaPrincipal()
{
return mTopLevelStorageAreaPrincipal;
}
NS_IMETHODIMP
LoadInfo::GetLoadingDocument(nsIDocument** aResult)
{
@ -1406,37 +1422,5 @@ LoadInfo::GetPerformanceStorage()
return mPerformanceStorage;
}
const nsTArray<nsString>&
LoadInfo::GetFirstPartyStorageAccessGrantedOrigins()
{
return mFirstPartyStorageAccessGrantedOrigins;
}
bool
LoadInfo::IsFirstPartyStorageAccessGrantedFor(nsIURI* aURI)
{
MOZ_ASSERT(aURI);
if (mFirstPartyStorageAccessGrantedOrigins.IsEmpty()) {
return false;
}
nsAutoString origin;
nsresult rv = nsContentUtils::GetUTFOrigin(aURI, origin);
if (NS_WARN_IF(NS_FAILED(rv))) {
return false;
}
return mFirstPartyStorageAccessGrantedOrigins.Contains(origin);
}
void
LoadInfo::AddFirstPartyStorageAccessGrantedFor(const nsAString& aOrigin)
{
if (!mFirstPartyStorageAccessGrantedOrigins.Contains(aOrigin)) {
mFirstPartyStorageAccessGrantedOrigins.AppendElement(aOrigin);
}
}
} // namespace net
} // namespace mozilla

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

@ -97,6 +97,7 @@ private:
nsIPrincipal* aTriggeringPrincipal,
nsIPrincipal* aPrincipalToInherit,
nsIPrincipal* aSandboxedLoadingPrincipal,
nsIPrincipal* aTopLevelStorageAreaPrincipal,
nsIURI* aResultPrincipalURI,
const Maybe<mozilla::dom::ClientInfo>& aClientInfo,
const Maybe<mozilla::dom::ClientInfo>& aReservedClientInfo,
@ -105,7 +106,6 @@ private:
nsSecurityFlags aSecurityFlags,
nsContentPolicyType aContentPolicyType,
LoadTainting aTainting,
const nsTArray<nsString>& aFirstPartyStorageAccessGrantedOrigins,
bool aUpgradeInsecureRequests,
bool aBrowserUpgradeInsecureRequests,
bool aBrowserWouldUpgradeInsecureRequests,
@ -160,6 +160,7 @@ private:
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
nsCOMPtr<nsIPrincipal> mPrincipalToInherit;
nsCOMPtr<nsIPrincipal> mSandboxedLoadingPrincipal;
nsCOMPtr<nsIPrincipal> mTopLevelStorageAreaPrincipal;
nsCOMPtr<nsIURI> mResultPrincipalURI;
Maybe<mozilla::dom::ClientInfo> mClientInfo;
@ -174,7 +175,6 @@ private:
nsSecurityFlags mSecurityFlags;
nsContentPolicyType mInternalContentPolicyType;
LoadTainting mTainting;
nsTArray<nsString> mFirstPartyStorageAccessGrantedOrigins;
bool mUpgradeInsecureRequests;
bool mBrowserUpgradeInsecureRequests;
bool mBrowserWouldUpgradeInsecureRequests;

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

@ -877,6 +877,19 @@ interface nsILoadInfo : nsISupports
*/
[noscript] readonly attribute nsIPrincipal sandboxedLoadingPrincipal;
/**
* Return the top-level storage area principal, which is the principal of
* the top-level window if it's not a 3rd party context, non tracking
* resource.
*/
[noscript] readonly attribute nsIPrincipal topLevelStorageAreaPrincipal;
/**
* A C++-friendly version of topLevelStorageAreaPrincipal.
*/
[noscript, notxpcom, nostdcall, binaryname(TopLevelStorageAreaPrincipal)]
nsIPrincipal binaryTopLevelStorageAreaPrincipal();
/**
* Note which client (i.e. global) initiated this network request. All
* nsGlobalWindow and WorkerPrivate can be converted to a ClientInfo to
@ -1020,15 +1033,4 @@ interface nsILoadInfo : nsISupports
*/
[noscript, nostdcall, notxpcom]
void SynthesizeServiceWorkerTainting(in LoadTainting aTainting);
/**
* This is the origin that has access storage granted also if 3rd party and
* in the tracking protection list.
*/
[noscript, notxpcom, nostdcall]
StringArrayRef getFirstPartyStorageAccessGrantedOrigins();
[noscript, notxpcom, nostdcall]
bool isFirstPartyStorageAccessGrantedFor(in nsIURI aURI);
[noscript, notxpcom, nostdcall]
void addFirstPartyStorageAccessGrantedFor(in AString aOrigin);
};

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

@ -5,6 +5,7 @@
#include "mozilla/net/CookieServiceChild.h"
#include "mozilla/net/NeckoChannelParams.h"
#include "mozilla/AntiTrackingCommon.h"
#include "mozilla/LoadInfo.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/ClearOnShutdown.h"
@ -182,14 +183,16 @@ CookieServiceChild::TrackCookieLoad(nsIChannel *aChannel)
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
if (httpChannel) {
isTrackingResource = httpChannel->GetIsTrackingResource();
if (isForeign && isTrackingResource &&
AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(httpChannel,
uri)) {
firstPartyStorageAccessGranted = true;
}
}
nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
mozilla::OriginAttributes attrs;
if (loadInfo) {
attrs = loadInfo->GetOriginAttributes();
if (loadInfo->IsFirstPartyStorageAccessGrantedFor(uri)) {
firstPartyStorageAccessGranted = true;
}
}
URIParams uriParams;
SerializeURI(uri, uriParams);
@ -573,14 +576,15 @@ CookieServiceChild::GetCookieStringInternal(nsIURI *aHostURI,
mThirdPartyUtil->IsThirdPartyChannel(aChannel, aHostURI, &isForeign);
bool isTrackingResource = false;
bool firstPartyStorageAccessGranted = false;
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
if (httpChannel) {
isTrackingResource = httpChannel->GetIsTrackingResource();
}
bool firstPartyStorageAccessGranted = false;
if (loadInfo->IsFirstPartyStorageAccessGrantedFor(aHostURI)) {
firstPartyStorageAccessGranted = true;
if (isForeign && isTrackingResource &&
AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(httpChannel,
aHostURI)) {
firstPartyStorageAccessGranted = true;
}
}
bool isSafeTopLevelNav = NS_IsSafeTopLevelNav(aChannel);
@ -629,9 +633,15 @@ CookieServiceChild::SetCookieStringInternal(nsIURI *aHostURI,
mThirdPartyUtil->IsThirdPartyChannel(aChannel, aHostURI, &isForeign);
bool isTrackingResource = false;
bool firstPartyStorageAccessGranted = false;
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
if (httpChannel) {
isTrackingResource = httpChannel->GetIsTrackingResource();
if (isForeign && isTrackingResource &&
AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(httpChannel,
aHostURI)) {
firstPartyStorageAccessGranted = true;
}
}
nsDependentCString cookieString(aCookieString);
@ -647,15 +657,11 @@ CookieServiceChild::SetCookieStringInternal(nsIURI *aHostURI,
URIParams channelURIParams;
SerializeURI(channelURI, channelURIParams);
bool firstPartyStorageAccessGranted = false;
mozilla::OriginAttributes attrs;
if (aChannel) {
nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
if (loadInfo) {
attrs = loadInfo->GetOriginAttributes();
if (loadInfo->IsFirstPartyStorageAccessGrantedFor(aHostURI)) {
firstPartyStorageAccessGranted = true;
}
}
}

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

@ -157,14 +157,15 @@ CookieServiceParent::TrackCookieLoad(nsIChannel *aChannel)
thirdPartyUtil->IsThirdPartyChannel(aChannel, uri, &isForeign);
bool isTrackingResource = false;
bool storageAccessGranted = false;
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
if (httpChannel) {
isTrackingResource = httpChannel->GetIsTrackingResource();
}
bool storageAccessGranted = false;
if (loadInfo && loadInfo->IsFirstPartyStorageAccessGrantedFor(uri)) {
storageAccessGranted = true;
if (isForeign && isTrackingResource &&
AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(httpChannel,
uri)) {
storageAccessGranted = true;
}
}
nsTArray<nsCookie*> foundCookieList;

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

@ -4,6 +4,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/AntiTrackingCommon.h"
#include "mozilla/Attributes.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/DebugOnly.h"
@ -2040,19 +2041,20 @@ nsCookieService::GetCookieStringCommon(nsIURI *aHostURI,
mThirdPartyUtil->IsThirdPartyChannel(aChannel, aHostURI, &isForeign);
bool isTrackingResource = false;
bool firstPartyStorageAccessGranted = false;
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
if (httpChannel) {
isTrackingResource = httpChannel->GetIsTrackingResource();
if (isForeign && isTrackingResource &&
AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(httpChannel,
aHostURI)) {
firstPartyStorageAccessGranted = true;
}
}
OriginAttributes attrs;
bool firstPartyStorageAccessGranted = false;
if (aChannel) {
nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
if (loadInfo && loadInfo->IsFirstPartyStorageAccessGrantedFor(aHostURI)) {
firstPartyStorageAccessGranted = true;
}
NS_GetOriginAttributes(aChannel, attrs);
}
@ -2146,19 +2148,21 @@ nsCookieService::SetCookieStringCommon(nsIURI *aHostURI,
mThirdPartyUtil->IsThirdPartyChannel(aChannel, aHostURI, &isForeign);
bool isTrackingResource = false;
bool firstPartyStorageAccessGranted = false;
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
if (httpChannel) {
isTrackingResource = httpChannel->GetIsTrackingResource();
if (isForeign && isTrackingResource &&
AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(httpChannel,
aHostURI)) {
firstPartyStorageAccessGranted = true;
}
}
OriginAttributes attrs;
bool firstPartyStorageAccessGranted = false;
if (aChannel) {
NS_GetOriginAttributes(aChannel, attrs);
nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
if (loadInfo && loadInfo->IsFirstPartyStorageAccessGrantedFor(aHostURI)) {
firstPartyStorageAccessGranted = true;
}
}
nsDependentCString cookieString(aCookieHeader);

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

@ -42,11 +42,11 @@ struct LoadInfoArgs
PrincipalInfo triggeringPrincipalInfo;
OptionalPrincipalInfo principalToInheritInfo;
OptionalPrincipalInfo sandboxedLoadingPrincipalInfo;
OptionalPrincipalInfo topLevelStorageAreaPrincipalInfo;
OptionalURIParams resultPrincipalURI;
uint32_t securityFlags;
uint32_t contentPolicyType;
uint32_t tainting;
nsString[] firstPartyStorageAccessGrantedOrigins;
bool upgradeInsecureRequests;
bool browserUpgradeInsecureRequests;
bool browserWouldUpgradeInsecureRequests;

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

@ -0,0 +1,255 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "AntiTrackingCommon.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/StaticPrefs.h"
#include "mozIThirdPartyUtil.h"
#include "nsContentUtils.h"
#include "nsGlobalWindowInner.h"
#include "nsIPermissionManager.h"
#include "nsIPrincipal.h"
#include "nsIURI.h"
#include "nsPIDOMWindow.h"
#include "prtime.h"
// Anti-tracking permission expiration
#define ANTITRACKING_EXPIRATION 2592000000 // 30 days.
#define ANTITRACKING_PERM_KEY "3rdPartyStorage"
using namespace mozilla;
using mozilla::dom::ContentChild;
namespace {
bool
GetParentPrincipalAndTrackingOrigin(nsPIDOMWindowInner* a3rdPartyTrackingWindow,
nsIPrincipal** aParentPrincipal,
nsACString& aTrackingOrigin)
{
#ifdef DEBUG
MOZ_ASSERT(nsContentUtils::IsThirdPartyWindowOrChannel(a3rdPartyTrackingWindow,
nullptr, nullptr));
MOZ_ASSERT(nsContentUtils::IsTrackingResourceWindow(a3rdPartyTrackingWindow));
#endif
nsGlobalWindowInner* innerWindow =
nsGlobalWindowInner::Cast(a3rdPartyTrackingWindow);
// Now we need the principal and the origin of the parent window.
nsCOMPtr<nsIPrincipal> parentPrincipal =
innerWindow->GetTopLevelStorageAreaPrincipal();
if (NS_WARN_IF(!parentPrincipal)) {
return false;
}
// Let's take the principal and the origin of the tracker.
nsIPrincipal* trackingPrincipal = innerWindow->GetPrincipal();
if (NS_WARN_IF(!trackingPrincipal)) {
return false;
}
nsresult rv = trackingPrincipal->GetOriginNoSuffix(aTrackingOrigin);
if (NS_WARN_IF(NS_FAILED(rv))) {
return false;
}
parentPrincipal.forget(aParentPrincipal);
return true;
};
void
CreatePermissionKey(const nsCString& aTrackingOrigin,
const nsCString& aGrantedOrigin,
nsACString& aPermissionKey)
{
if (aTrackingOrigin == aGrantedOrigin) {
aPermissionKey = nsPrintfCString(ANTITRACKING_PERM_KEY "^%s",
aTrackingOrigin.get());
return;
}
aPermissionKey = nsPrintfCString(ANTITRACKING_PERM_KEY "^%s^%s",
aTrackingOrigin.get(),
aGrantedOrigin.get());
}
} // anonymous
/* static */ void
AntiTrackingCommon::AddFirstPartyStorageAccessGrantedFor(const nsAString& aOrigin,
nsPIDOMWindowInner* a3rdPartyTrackingWindow)
{
MOZ_ASSERT(a3rdPartyTrackingWindow);
if (!StaticPrefs::privacy_restrict3rdpartystorage_enabled()) {
return;
}
nsCOMPtr<nsIPrincipal> parentPrincipal;
nsAutoCString trackingOrigin;
if (!GetParentPrincipalAndTrackingOrigin(a3rdPartyTrackingWindow,
getter_AddRefs(parentPrincipal),
trackingOrigin)) {
return;
}
NS_ConvertUTF16toUTF8 grantedOrigin(aOrigin);
if (XRE_IsParentProcess()) {
SaveFirstPartyStorageAccessGrantedForOriginOnParentProcess(parentPrincipal,
trackingOrigin,
grantedOrigin);
return;
}
ContentChild* cc = ContentChild::GetSingleton();
MOZ_ASSERT(cc);
// This is not really secure, because here we have the content process sending
// the request of storing a permission.
Unused << cc->SendFirstPartyStorageAccessGrantedForOrigin(IPC::Principal(parentPrincipal),
trackingOrigin,
grantedOrigin);
}
/* static */ void
AntiTrackingCommon::SaveFirstPartyStorageAccessGrantedForOriginOnParentProcess(nsIPrincipal* aParentPrincipal,
const nsCString& aTrackingOrigin,
const nsCString& aGrantedOrigin)
{
MOZ_ASSERT(XRE_IsParentProcess());
if (NS_WARN_IF(!aParentPrincipal)) {
// The child process is sending something wrong. Let's ignore it.
return;
}
nsCOMPtr<nsIPermissionManager> pm = services::GetPermissionManager();
if (NS_WARN_IF(!pm)) {
return;
}
int64_t when = (PR_Now() / PR_USEC_PER_MSEC) + ANTITRACKING_EXPIRATION;
nsAutoCString type;
CreatePermissionKey(aTrackingOrigin, aGrantedOrigin, type);
nsresult rv = pm->AddFromPrincipal(aParentPrincipal, type.get(),
nsIPermissionManager::ALLOW_ACTION,
nsIPermissionManager::EXPIRE_TIME, when);
Unused << NS_WARN_IF(NS_FAILED(rv));
}
bool
AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(nsPIDOMWindowInner* a3rdPartyTrackingWindow,
nsIURI* aURI)
{
MOZ_ASSERT(a3rdPartyTrackingWindow);
MOZ_ASSERT(aURI);
if (!StaticPrefs::privacy_restrict3rdpartystorage_enabled()) {
return true;
}
if (!nsContentUtils::IsThirdPartyWindowOrChannel(a3rdPartyTrackingWindow,
nullptr, nullptr) ||
!nsContentUtils::IsTrackingResourceWindow(a3rdPartyTrackingWindow)) {
return true;
}
nsCOMPtr<nsIPrincipal> parentPrincipal;
nsAutoCString trackingOrigin;
if (!GetParentPrincipalAndTrackingOrigin(a3rdPartyTrackingWindow,
getter_AddRefs(parentPrincipal),
trackingOrigin)) {
return false;
}
nsAutoString origin;
nsresult rv = nsContentUtils::GetUTFOrigin(aURI, origin);
if (NS_WARN_IF(NS_FAILED(rv))) {
return false;
}
nsAutoCString type;
CreatePermissionKey(trackingOrigin, NS_ConvertUTF16toUTF8(origin), type);
nsCOMPtr<nsIPermissionManager> pm = services::GetPermissionManager();
if (NS_WARN_IF(!pm)) {
return false;
}
uint32_t result = 0;
rv = pm->TestPermissionFromPrincipal(parentPrincipal, type.get(), &result);
if (NS_WARN_IF(NS_FAILED(rv))) {
return false;
}
return result == nsIPermissionManager::ALLOW_ACTION;
}
bool
AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(nsIHttpChannel* aChannel,
nsIURI* aURI)
{
MOZ_ASSERT(aURI);
MOZ_ASSERT(aChannel);
MOZ_ASSERT(aChannel->GetIsTrackingResource());
#ifdef DEBUG
nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil = do_GetService(THIRDPARTYUTIL_CONTRACTID);
bool is3rdPartyContext = false;
thirdPartyUtil->IsThirdPartyChannel(aChannel, aURI, &is3rdPartyContext);
MOZ_ASSERT(is3rdPartyContext);
#endif
nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
if (!loadInfo) {
return true;
}
nsIPrincipal* parentPrincipal = loadInfo->TopLevelStorageAreaPrincipal();
if (NS_WARN_IF(!parentPrincipal)) {
return true;
}
nsCOMPtr<nsIURI> trackingURI;
nsresult rv = aChannel->GetURI(getter_AddRefs(trackingURI));
if (NS_WARN_IF(NS_FAILED(rv))) {
return true;
}
nsAutoString trackingOrigin;
rv = nsContentUtils::GetUTFOrigin(trackingURI, trackingOrigin);
if (NS_WARN_IF(NS_FAILED(rv))) {
return false;
}
nsAutoString origin;
rv = nsContentUtils::GetUTFOrigin(aURI, origin);
if (NS_WARN_IF(NS_FAILED(rv))) {
return false;
}
nsAutoCString type;
CreatePermissionKey(NS_ConvertUTF16toUTF8(trackingOrigin),
NS_ConvertUTF16toUTF8(origin), type);
nsCOMPtr<nsIPermissionManager> pm = services::GetPermissionManager();
if (NS_WARN_IF(!pm)) {
return false;
}
uint32_t result = 0;
rv = pm->TestPermissionFromPrincipal(parentPrincipal, type.get(), &result);
if (NS_WARN_IF(NS_FAILED(rv))) {
return false;
}
return result == nsIPermissionManager::ALLOW_ACTION;
}

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

@ -0,0 +1,51 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_antitrackingservice_h
#define mozilla_antitrackingservice_h
#include "nsString.h"
class nsIHttpChannel;
class nsIPrincipal;
class nsIURI;
class nsPIDOMWindowInner;
namespace mozilla {
class AntiTrackingCommon final
{
public:
// This method returns true if the URI has first party storage access when
// loaded inside the passed 3rd party context tracking resource window.
static bool
IsFirstPartyStorageAccessGrantedFor(nsPIDOMWindowInner* a3rdPartyTrackingWindow,
nsIURI* aURI);
// This can be called only if the a3rdPartyTrackingChannel is _really_ a 3rd
// party context and marked as tracking resource.
// It returns true if the URI has access to the first party storage.
static bool
IsFirstPartyStorageAccessGrantedFor(nsIHttpChannel* a3rdPartyTrackingChannel,
nsIURI* aURI);
// Grant the permission for aOrigin to have access to the first party storage
// when loaded in that particular 3rd party context.
static void
AddFirstPartyStorageAccessGrantedFor(const nsAString& aOrigin,
nsPIDOMWindowInner* a3rdPartyTrackingWindow);
// For IPC only.
static void
SaveFirstPartyStorageAccessGrantedForOriginOnParentProcess(nsIPrincipal* aPrincipal,
const nsCString& aParentOrigin,
const nsCString& aGrantedOrigin);
};
} // namespace mozilla
#endif // mozilla_antitrackingservice_h

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

@ -7,4 +7,16 @@
with Files('**'):
BUG_COMPONENT = ('Core', 'DOM: Security')
EXPORTS.mozilla = [
'AntiTrackingCommon.h',
]
UNIFIED_SOURCES += [
'AntiTrackingCommon.cpp',
]
include('/ipc/chromium/chromium-config.mozbuild')
FINAL_LIBRARY = 'xul'
BROWSER_CHROME_MANIFESTS += ['test/browser/browser.ini']