mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-29 02:17:45 -10:00
Bug 1475599 - part 10 - CookieStore API - CHIP implementation shared between Document and CookieStore, r=cookie-reviewers,valentin
Differential Revision: https://phabricator.services.mozilla.com/D220288
This commit is contained in:
1 parent
dcacfadc85
commit
1249438a9a
7 files changed
+283
-129
No files matched your search
@@ -6653,8 +6653,9 @@ void Document::GetCookie(nsAString& aCookie, ErrorResult& aRv) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (thirdParty && !CookieCommons::ShouldIncludeCrossSiteCookieForDocument(
|
||||
cookie, this)) {
|
||||
if (thirdParty && !CookieCommons::ShouldIncludeCrossSiteCookie(
|
||||
cookie, CookieJarSettings()->GetPartitionForeign(),
|
||||
IsInPrivateBrowsing(), UsingStorageAccess())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -6789,8 +6790,9 @@ void Document::SetCookie(const nsAString& aCookieString, ErrorResult& aRv) {
|
||||
nullptr, &thirdParty);
|
||||
}
|
||||
|
||||
if (thirdParty &&
|
||||
!CookieCommons::ShouldIncludeCrossSiteCookieForDocument(cookie, this)) {
|
||||
if (thirdParty && !CookieCommons::ShouldIncludeCrossSiteCookie(
|
||||
cookie, CookieJarSettings()->GetPartitionForeign(),
|
||||
IsInPrivateBrowsing(), UsingStorageAccess())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "nsIPrincipal.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsSandboxFlags.h"
|
||||
#include "ThirdPartyUtil.h"
|
||||
|
||||
using namespace mozilla::net;
|
||||
|
||||
@@ -193,6 +194,46 @@ void ResolvePromiseAsync(Promise* aPromise) {
|
||||
[promise = RefPtr(aPromise)] { promise->MaybeResolveWithUndefined(); }));
|
||||
}
|
||||
|
||||
bool GetContextAttributes(CookieStore* aCookieStore, bool* aThirdPartyContext,
|
||||
bool* aPartitionForeign, bool* aUsingStorageAccess,
|
||||
Promise* aPromise) {
|
||||
MOZ_ASSERT(aCookieStore);
|
||||
MOZ_ASSERT(aThirdPartyContext);
|
||||
MOZ_ASSERT(aPartitionForeign);
|
||||
MOZ_ASSERT(aUsingStorageAccess);
|
||||
MOZ_ASSERT(aPromise);
|
||||
|
||||
if (NS_IsMainThread()) {
|
||||
nsCOMPtr<nsPIDOMWindowInner> window = aCookieStore->GetOwnerWindow();
|
||||
MOZ_ASSERT(window);
|
||||
|
||||
ThirdPartyUtil* thirdPartyUtil = ThirdPartyUtil::GetInstance();
|
||||
if (thirdPartyUtil) {
|
||||
Unused << thirdPartyUtil->IsThirdPartyWindow(window->GetOuterWindow(),
|
||||
nullptr, aThirdPartyContext);
|
||||
}
|
||||
|
||||
nsCOMPtr<Document> document = window->GetExtantDoc();
|
||||
if (NS_WARN_IF(!document)) {
|
||||
aPromise->MaybeReject(NS_ERROR_DOM_SECURITY_ERR);
|
||||
return false;
|
||||
}
|
||||
|
||||
*aPartitionForeign = document->CookieJarSettings()->GetPartitionForeign();
|
||||
*aUsingStorageAccess = document->UsingStorageAccess();
|
||||
return true;
|
||||
}
|
||||
|
||||
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
||||
MOZ_ASSERT(workerPrivate);
|
||||
|
||||
*aThirdPartyContext = workerPrivate->IsThirdPartyContext();
|
||||
*aPartitionForeign =
|
||||
workerPrivate->CookieJarSettings()->GetPartitionForeign();
|
||||
*aUsingStorageAccess = workerPrivate->UsingStorageAccess();
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(CookieStore)
|
||||
@@ -324,6 +365,15 @@ already_AddRefed<Promise> CookieStore::Set(const CookieInit& aOptions,
|
||||
return;
|
||||
}
|
||||
|
||||
bool thirdPartyContext = true;
|
||||
bool partitionForeign = true;
|
||||
bool usingStorageAccess = false;
|
||||
|
||||
if (!GetContextAttributes(self, &thirdPartyContext, &partitionForeign,
|
||||
&usingStorageAccess, promise)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!self->MaybeCreateActor()) {
|
||||
promise->MaybeRejectWithNotAllowedError("Permission denied");
|
||||
return;
|
||||
@@ -348,8 +398,9 @@ already_AddRefed<Promise> CookieStore::Set(const CookieInit& aOptions,
|
||||
self->mActor->SendSetRequest(
|
||||
aOptions.mDomain.IsEmpty() ? nsString(baseDomain)
|
||||
: nsString(aOptions.mDomain),
|
||||
cookiePrincipal->OriginAttributesRef(),
|
||||
nsString(aOptions.mName), nsString(aOptions.mValue),
|
||||
cookiePrincipal->OriginAttributesRef(), thirdPartyContext,
|
||||
partitionForeign, usingStorageAccess, nsString(aOptions.mName),
|
||||
nsString(aOptions.mValue),
|
||||
// If expires is not set, it's a session cookie.
|
||||
aOptions.mExpires.IsNull(),
|
||||
aOptions.mExpires.IsNull()
|
||||
@@ -437,6 +488,15 @@ already_AddRefed<Promise> CookieStore::Delete(
|
||||
return;
|
||||
}
|
||||
|
||||
bool thirdPartyContext = true;
|
||||
bool partitionForeign = true;
|
||||
bool usingStorageAccess = false;
|
||||
|
||||
if (!GetContextAttributes(self, &thirdPartyContext, &partitionForeign,
|
||||
&usingStorageAccess, promise)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!self->MaybeCreateActor()) {
|
||||
promise->MaybeRejectWithNotAllowedError("Permission denied");
|
||||
return;
|
||||
@@ -461,9 +521,9 @@ already_AddRefed<Promise> CookieStore::Delete(
|
||||
self->mActor->SendDeleteRequest(
|
||||
aOptions.mDomain.IsEmpty() ? nsString(baseDomain)
|
||||
: nsString(aOptions.mDomain),
|
||||
cookiePrincipal->OriginAttributesRef(),
|
||||
nsString(aOptions.mName), path, aOptions.mPartitioned,
|
||||
operationID);
|
||||
cookiePrincipal->OriginAttributesRef(), thirdPartyContext,
|
||||
partitionForeign, usingStorageAccess, nsString(aOptions.mName),
|
||||
path, aOptions.mPartitioned, operationID);
|
||||
if (NS_WARN_IF(!ipcPromise)) {
|
||||
promise->MaybeResolveWithUndefined();
|
||||
return;
|
||||
@@ -528,8 +588,10 @@ already_AddRefed<Promise> CookieStore::GetInternal(
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPrincipal> cookiePrincipal;
|
||||
nsCOMPtr<nsIPrincipal> partitionedCookiePrincipal;
|
||||
switch (CookieCommons::CheckGlobalAndRetrieveCookiePrincipals(
|
||||
MaybeGetDocument(), getter_AddRefs(cookiePrincipal), nullptr)) {
|
||||
MaybeGetDocument(), getter_AddRefs(cookiePrincipal),
|
||||
getter_AddRefs(partitionedCookiePrincipal))) {
|
||||
case CookieCommons::SecurityChecksResult::eSandboxedError:
|
||||
[[fallthrough]];
|
||||
|
||||
@@ -549,7 +611,9 @@ already_AddRefed<Promise> CookieStore::GetInternal(
|
||||
NS_DispatchToCurrentThread(NS_NewRunnableFunction(
|
||||
__func__,
|
||||
[self = RefPtr(this), promise = RefPtr(promise), aOptions,
|
||||
cookiePrincipal = RefPtr(cookiePrincipal.get()), aOnlyTheFirstMatch]() {
|
||||
cookiePrincipal = RefPtr(cookiePrincipal.get()),
|
||||
partitionedCookiePrincipal = RefPtr(partitionedCookiePrincipal.get()),
|
||||
aOnlyTheFirstMatch]() {
|
||||
nsAutoString name;
|
||||
if (aOptions.mName.WasPassed()) {
|
||||
name = aOptions.mName.Value();
|
||||
@@ -628,6 +692,15 @@ already_AddRefed<Promise> CookieStore::GetInternal(
|
||||
}
|
||||
}
|
||||
|
||||
bool thirdPartyContext = true;
|
||||
bool partitionForeign = true;
|
||||
bool usingStorageAccess = false;
|
||||
|
||||
if (!GetContextAttributes(self, &thirdPartyContext, &partitionForeign,
|
||||
&usingStorageAccess, promise)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!self->MaybeCreateActor()) {
|
||||
promise->MaybeRejectWithNotAllowedError("Permission denied");
|
||||
return;
|
||||
@@ -641,11 +714,15 @@ already_AddRefed<Promise> CookieStore::GetInternal(
|
||||
}
|
||||
|
||||
RefPtr<CookieStoreChild::GetRequestPromise> ipcPromise =
|
||||
self->mActor->SendGetRequest(NS_ConvertUTF8toUTF16(baseDomain),
|
||||
cookiePrincipal->OriginAttributesRef(),
|
||||
aOptions.mName.WasPassed(),
|
||||
nsString(name), path,
|
||||
aOnlyTheFirstMatch);
|
||||
self->mActor->SendGetRequest(
|
||||
NS_ConvertUTF8toUTF16(baseDomain),
|
||||
cookiePrincipal->OriginAttributesRef(),
|
||||
partitionedCookiePrincipal
|
||||
? Some(partitionedCookiePrincipal->OriginAttributesRef())
|
||||
: Nothing(),
|
||||
thirdPartyContext, partitionForeign, usingStorageAccess,
|
||||
aOptions.mName.WasPassed(), nsString(name), path,
|
||||
aOnlyTheFirstMatch);
|
||||
if (NS_WARN_IF(!ipcPromise)) {
|
||||
promise->MaybeResolveWithUndefined();
|
||||
return;
|
||||
|
||||
@@ -9,11 +9,13 @@
|
||||
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/ipc/BackgroundParent.h"
|
||||
#include "mozilla/net/Cookie.h"
|
||||
#include "mozilla/net/CookieCommons.h"
|
||||
#include "mozilla/net/CookieServiceParent.h"
|
||||
#include "mozilla/net/NeckoParent.h"
|
||||
#include "mozilla/Unused.h"
|
||||
#include "nsICookieManager.h"
|
||||
#include "nsICookieService.h"
|
||||
#include "nsProxyRelease.h"
|
||||
|
||||
using namespace mozilla::ipc;
|
||||
@@ -67,20 +69,26 @@ CookieStoreParent::~CookieStoreParent() {
|
||||
|
||||
mozilla::ipc::IPCResult CookieStoreParent::RecvGetRequest(
|
||||
const nsString& aDomain, const OriginAttributes& aOriginAttributes,
|
||||
const bool& aMatchName, const nsString& aName, const nsCString& aPath,
|
||||
const bool& aOnlyFirstMatch, GetRequestResolver&& aResolver) {
|
||||
const Maybe<OriginAttributes>& aPartitionedOriginAttributes,
|
||||
const bool& aThirdPartyContext, const bool& aPartitionForeign,
|
||||
const bool& aUsingStorageAccess, const bool& aMatchName,
|
||||
const nsString& aName, const nsCString& aPath, const bool& aOnlyFirstMatch,
|
||||
GetRequestResolver&& aResolver) {
|
||||
AssertIsOnBackgroundThread();
|
||||
|
||||
InvokeAsync(GetMainThreadSerialEventTarget(), __func__,
|
||||
[self = RefPtr(this), aDomain, aOriginAttributes, aMatchName,
|
||||
aName, aPath, aOnlyFirstMatch]() {
|
||||
CopyableTArray<CookieData> results;
|
||||
self->GetRequestOnMainThread(aDomain, aOriginAttributes,
|
||||
aMatchName, aName, aPath,
|
||||
aOnlyFirstMatch, results);
|
||||
return GetRequestPromise::CreateAndResolve(std::move(results),
|
||||
__func__);
|
||||
})
|
||||
InvokeAsync(
|
||||
GetMainThreadSerialEventTarget(), __func__,
|
||||
[self = RefPtr(this), aDomain, aOriginAttributes,
|
||||
aPartitionedOriginAttributes, aThirdPartyContext, aPartitionForeign,
|
||||
aUsingStorageAccess, aMatchName, aName, aPath, aOnlyFirstMatch]() {
|
||||
CopyableTArray<CookieData> results;
|
||||
self->GetRequestOnMainThread(
|
||||
aDomain, aOriginAttributes, aPartitionedOriginAttributes,
|
||||
aThirdPartyContext, aPartitionForeign, aUsingStorageAccess,
|
||||
aMatchName, aName, aPath, aOnlyFirstMatch, results);
|
||||
return GetRequestPromise::CreateAndResolve(std::move(results),
|
||||
__func__);
|
||||
})
|
||||
->Then(GetCurrentSerialEventTarget(), __func__,
|
||||
[aResolver = std::move(aResolver)](
|
||||
const GetRequestPromise::ResolveOrRejectValue& aResult) {
|
||||
@@ -93,10 +101,11 @@ mozilla::ipc::IPCResult CookieStoreParent::RecvGetRequest(
|
||||
|
||||
mozilla::ipc::IPCResult CookieStoreParent::RecvSetRequest(
|
||||
const nsString& aDomain, const OriginAttributes& aOriginAttributes,
|
||||
const nsString& aName, const nsString& aValue, const bool& aSession,
|
||||
const int64_t& aExpires, const nsString& aPath, const int32_t& aSameSite,
|
||||
const bool& aPartitioned, const nsID& aOperationID,
|
||||
SetRequestResolver&& aResolver) {
|
||||
const bool& aThirdPartyContext, const bool& aPartitionForeign,
|
||||
const bool& aUsingStorageAccess, const nsString& aName,
|
||||
const nsString& aValue, const bool& aSession, const int64_t& aExpires,
|
||||
const nsString& aPath, const int32_t& aSameSite, const bool& aPartitioned,
|
||||
const nsID& aOperationID, SetRequestResolver&& aResolver) {
|
||||
AssertIsOnBackgroundThread();
|
||||
|
||||
RefPtr<ThreadsafeContentParentHandle> parent =
|
||||
@@ -104,11 +113,14 @@ mozilla::ipc::IPCResult CookieStoreParent::RecvSetRequest(
|
||||
|
||||
InvokeAsync(GetMainThreadSerialEventTarget(), __func__,
|
||||
[self = RefPtr(this), parent = RefPtr(parent), aDomain,
|
||||
aOriginAttributes, aName, aValue, aSession, aExpires, aPath,
|
||||
aOriginAttributes, aThirdPartyContext, aPartitionForeign,
|
||||
aUsingStorageAccess, aName, aValue, aSession, aExpires, aPath,
|
||||
aSameSite, aPartitioned, aOperationID]() {
|
||||
bool waitForNotification = self->SetRequestOnMainThread(
|
||||
parent, aDomain, aOriginAttributes, aName, aValue, aSession,
|
||||
aExpires, aPath, aSameSite, aPartitioned, aOperationID);
|
||||
parent, aDomain, aOriginAttributes, aThirdPartyContext,
|
||||
aPartitionForeign, aUsingStorageAccess, aName, aValue,
|
||||
aSession, aExpires, aPath, aSameSite, aPartitioned,
|
||||
aOperationID);
|
||||
return SetDeleteRequestPromise::CreateAndResolve(
|
||||
waitForNotification, __func__);
|
||||
})
|
||||
@@ -124,22 +136,27 @@ mozilla::ipc::IPCResult CookieStoreParent::RecvSetRequest(
|
||||
|
||||
mozilla::ipc::IPCResult CookieStoreParent::RecvDeleteRequest(
|
||||
const nsString& aDomain, const OriginAttributes& aOriginAttributes,
|
||||
const nsString& aName, const nsString& aPath, const bool& aPartitioned,
|
||||
const nsID& aOperationID, DeleteRequestResolver&& aResolver) {
|
||||
const bool& aThirdPartyContext, const bool& aPartitionForeign,
|
||||
const bool& aUsingStorageAccess, const nsString& aName,
|
||||
const nsString& aPath, const bool& aPartitioned, const nsID& aOperationID,
|
||||
DeleteRequestResolver&& aResolver) {
|
||||
AssertIsOnBackgroundThread();
|
||||
|
||||
RefPtr<ThreadsafeContentParentHandle> parent =
|
||||
BackgroundParent::GetContentParentHandle(Manager());
|
||||
|
||||
InvokeAsync(GetMainThreadSerialEventTarget(), __func__,
|
||||
[self = RefPtr(this), parent = RefPtr(parent), aDomain,
|
||||
aOriginAttributes, aName, aPath, aPartitioned, aOperationID]() {
|
||||
bool waitForNotification = self->DeleteRequestOnMainThread(
|
||||
parent, aDomain, aOriginAttributes, aName, aPath,
|
||||
aPartitioned, aOperationID);
|
||||
return SetDeleteRequestPromise::CreateAndResolve(
|
||||
waitForNotification, __func__);
|
||||
})
|
||||
InvokeAsync(
|
||||
GetMainThreadSerialEventTarget(), __func__,
|
||||
[self = RefPtr(this), parent = RefPtr(parent), aDomain, aOriginAttributes,
|
||||
aThirdPartyContext, aPartitionForeign, aUsingStorageAccess, aName, aPath,
|
||||
aPartitioned, aOperationID]() {
|
||||
bool waitForNotification = self->DeleteRequestOnMainThread(
|
||||
parent, aDomain, aOriginAttributes, aThirdPartyContext,
|
||||
aPartitionForeign, aUsingStorageAccess, aName, aPath, aPartitioned,
|
||||
aOperationID);
|
||||
return SetDeleteRequestPromise::CreateAndResolve(waitForNotification,
|
||||
__func__);
|
||||
})
|
||||
->Then(GetCurrentSerialEventTarget(), __func__,
|
||||
[aResolver = std::move(aResolver)](
|
||||
const SetDeleteRequestPromise::ResolveOrRejectValue& aResult) {
|
||||
@@ -158,69 +175,63 @@ mozilla::ipc::IPCResult CookieStoreParent::RecvClose() {
|
||||
|
||||
void CookieStoreParent::GetRequestOnMainThread(
|
||||
const nsAString& aDomain, const OriginAttributes& aOriginAttributes,
|
||||
const Maybe<OriginAttributes>& aPartitionedOriginAttributes,
|
||||
bool aThirdPartyContext, bool aPartitionForeign, bool aUsingStorageAccess,
|
||||
bool aMatchName, const nsAString& aName, const nsACString& aPath,
|
||||
bool aOnlyFirstMatch, nsTArray<CookieData>& aResults) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsCOMPtr<nsICookieManager> service =
|
||||
do_GetService(NS_COOKIEMANAGER_CONTRACTID);
|
||||
nsCOMPtr<nsICookieService> service =
|
||||
do_GetService(NS_COOKIESERVICE_CONTRACTID);
|
||||
if (!service) {
|
||||
return;
|
||||
}
|
||||
|
||||
OriginAttributes attrs(aOriginAttributes);
|
||||
nsTArray<RefPtr<nsICookie>> results;
|
||||
nsresult rv = service->GetCookiesFromHostNative(
|
||||
NS_ConvertUTF16toUTF8(aDomain), &attrs, results);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return;
|
||||
}
|
||||
|
||||
NS_ConvertUTF16toUTF8 matchName(aName);
|
||||
|
||||
nsTArray<OriginAttributes> attrsList;
|
||||
attrsList.AppendElement(aOriginAttributes);
|
||||
|
||||
if (aPartitionedOriginAttributes) {
|
||||
attrsList.AppendElement(aPartitionedOriginAttributes.value());
|
||||
}
|
||||
|
||||
nsTArray<CookieData> list;
|
||||
for (nsICookie* cookie : results) {
|
||||
bool isHttpOnly;
|
||||
rv = cookie->GetIsHttpOnly(&isHttpOnly);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return;
|
||||
|
||||
for (const OriginAttributes& attrs : attrsList) {
|
||||
nsTArray<RefPtr<Cookie>> cookies;
|
||||
service->GetCookiesFromHost(NS_ConvertUTF16toUTF8(aDomain), attrs, cookies);
|
||||
|
||||
for (Cookie* cookie : cookies) {
|
||||
if (cookie->IsHttpOnly()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (aThirdPartyContext &&
|
||||
!CookieCommons::ShouldIncludeCrossSiteCookie(
|
||||
cookie, aPartitionForeign, attrs.IsPrivateBrowsing(),
|
||||
aUsingStorageAccess)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (aMatchName && !matchName.Equals(cookie->Name())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!net::CookieCommons::PathMatches(cookie->Path(), aPath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CookieData* data = list.AppendElement();
|
||||
data->name() = NS_ConvertUTF8toUTF16(cookie->Name());
|
||||
data->value() = NS_ConvertUTF8toUTF16(cookie->Value());
|
||||
|
||||
if (aOnlyFirstMatch) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isHttpOnly) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nsAutoCString name;
|
||||
rv = cookie->GetName(name);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (aMatchName && !matchName.Equals(name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nsAutoCString cookiePath;
|
||||
rv = cookie->GetPath(cookiePath);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!net::CookieCommons::PathMatches(cookiePath, aPath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nsAutoCString value;
|
||||
rv = cookie->GetValue(value);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return;
|
||||
}
|
||||
|
||||
CookieData* data = list.AppendElement();
|
||||
data->name() = NS_ConvertUTF8toUTF16(name);
|
||||
data->value() = NS_ConvertUTF8toUTF16(value);
|
||||
|
||||
if (aOnlyFirstMatch) {
|
||||
if (!list.IsEmpty() && aOnlyFirstMatch) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -230,7 +241,8 @@ void CookieStoreParent::GetRequestOnMainThread(
|
||||
|
||||
bool CookieStoreParent::SetRequestOnMainThread(
|
||||
ThreadsafeContentParentHandle* aParent, const nsAString& aDomain,
|
||||
const OriginAttributes& aOriginAttributes, const nsAString& aName,
|
||||
const OriginAttributes& aOriginAttributes, bool aThirdPartyContext,
|
||||
bool aPartitionForeign, bool aUsingStorageAccess, const nsAString& aName,
|
||||
const nsAString& aValue, bool aSession, int64_t aExpires,
|
||||
const nsAString& aPath, int32_t aSameSite, bool aPartitioned,
|
||||
const nsID& aOperationID) {
|
||||
@@ -242,6 +254,14 @@ bool CookieStoreParent::SetRequestOnMainThread(
|
||||
return false;
|
||||
}
|
||||
|
||||
if (aThirdPartyContext &&
|
||||
!CookieCommons::ShouldIncludeCrossSiteCookie(
|
||||
aSameSite, aPartitioned && !aOriginAttributes.mPartitionKey.IsEmpty(),
|
||||
aPartitionForeign, aOriginAttributes.IsPrivateBrowsing(),
|
||||
aUsingStorageAccess)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsICookieManager> service =
|
||||
do_GetService(NS_COOKIEMANAGER_CONTRACTID);
|
||||
if (!service) {
|
||||
@@ -278,7 +298,8 @@ bool CookieStoreParent::SetRequestOnMainThread(
|
||||
|
||||
bool CookieStoreParent::DeleteRequestOnMainThread(
|
||||
ThreadsafeContentParentHandle* aParent, const nsAString& aDomain,
|
||||
const OriginAttributes& aOriginAttributes, const nsAString& aName,
|
||||
const OriginAttributes& aOriginAttributes, bool aThirdPartyContext,
|
||||
bool aPartitionForeign, bool aUsingStorageAccess, const nsAString& aName,
|
||||
const nsAString& aPath, bool aPartitioned, const nsID& aOperationID) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
@@ -335,6 +356,22 @@ bool CookieStoreParent::DeleteRequestOnMainThread(
|
||||
|
||||
if (isPartitioned != aPartitioned) continue;
|
||||
|
||||
if (aThirdPartyContext) {
|
||||
int32_t sameSiteAttr = 0;
|
||||
rv = cookie->GetSameSite(&sameSiteAttr);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CookieCommons::ShouldIncludeCrossSiteCookie(
|
||||
sameSiteAttr,
|
||||
isPartitioned && !aOriginAttributes.mPartitionKey.IsEmpty(),
|
||||
aPartitionForeign, attrs.IsPrivateBrowsing(),
|
||||
aUsingStorageAccess)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool notified = false;
|
||||
auto notificationCb = [&]() { notified = true; };
|
||||
|
||||
|
||||
@@ -32,46 +32,55 @@ class CookieStoreParent final : public PCookieStoreParent {
|
||||
|
||||
mozilla::ipc::IPCResult RecvGetRequest(
|
||||
const nsString& aDomain, const OriginAttributes& aOriginAttributes,
|
||||
const bool& aMatchName, const nsString& aName, const nsCString& aPath,
|
||||
const Maybe<OriginAttributes>& aPartitionedOriginAttributes,
|
||||
const bool& aThirdPartyContext, const bool& aPartitionForeign,
|
||||
const bool& aUsingStorageAccess, const bool& aMatchName,
|
||||
const nsString& aName, const nsCString& aPath,
|
||||
const bool& aOnlyFirstMatch, GetRequestResolver&& aResolver);
|
||||
|
||||
mozilla::ipc::IPCResult RecvSetRequest(
|
||||
const nsString& aDomain, const OriginAttributes& aOriginAttributes,
|
||||
const nsString& aName, const nsString& aValue, const bool& aSession,
|
||||
const int64_t& aExpires, const nsString& aPath, const int32_t& aSameSite,
|
||||
const bool& aPartitioned, const nsID& aOperationID,
|
||||
SetRequestResolver&& aResolver);
|
||||
const bool& aThirdPartyContext, const bool& aPartitionForeign,
|
||||
const bool& aUsingStorageAccess, const nsString& aName,
|
||||
const nsString& aValue, const bool& aSession, const int64_t& aExpires,
|
||||
const nsString& aPath, const int32_t& aSameSite, const bool& aPartitioned,
|
||||
const nsID& aOperationID, SetRequestResolver&& aResolver);
|
||||
|
||||
mozilla::ipc::IPCResult RecvDeleteRequest(
|
||||
const nsString& aDomain, const OriginAttributes& aOriginAttributes,
|
||||
const nsString& aName, const nsString& aPath, const bool& aPartitioned,
|
||||
const nsID& aOperationID, DeleteRequestResolver&& aResolver);
|
||||
const bool& aThirdPartyContext, const bool& aPartitionForeign,
|
||||
const bool& aUsingStorageAccess, const nsString& aName,
|
||||
const nsString& aPath, const bool& aPartitioned, const nsID& aOperationID,
|
||||
DeleteRequestResolver&& aResolver);
|
||||
|
||||
mozilla::ipc::IPCResult RecvClose();
|
||||
|
||||
void GetRequestOnMainThread(const nsAString& aDomain,
|
||||
const OriginAttributes& aOriginAttributes,
|
||||
bool aMatchName, const nsAString& aName,
|
||||
const nsACString& aPath, bool aOnlyFirstMatch,
|
||||
nsTArray<CookieData>& aResults);
|
||||
void GetRequestOnMainThread(
|
||||
const nsAString& aDomain, const OriginAttributes& aOriginAttributes,
|
||||
const Maybe<OriginAttributes>& aPartitionedOriginAttributes,
|
||||
bool aThirdPartyContext, bool aPartitionForeign, bool aUsingStorageAccess,
|
||||
bool aMatchName, const nsAString& aName, const nsACString& aPath,
|
||||
bool aOnlyFirstMatch, nsTArray<CookieData>& aResults);
|
||||
|
||||
// Returns true if a cookie notification has been generated while completing
|
||||
// the operation.
|
||||
bool SetRequestOnMainThread(ThreadsafeContentParentHandle* aParent,
|
||||
const nsAString& aDomain,
|
||||
const OriginAttributes& aOriginAttributes,
|
||||
const nsAString& aName, const nsAString& aValue,
|
||||
bool aSession, int64_t aExpires,
|
||||
const nsAString& aPath, int32_t aSameSite,
|
||||
bool aPartitioned, const nsID& aOperationID);
|
||||
bool aThirdPartyContext, bool aPartitionForeign,
|
||||
bool aUsingStorageAccess, const nsAString& aName,
|
||||
const nsAString& aValue, bool aSession,
|
||||
int64_t aExpires, const nsAString& aPath,
|
||||
int32_t aSameSite, bool aPartitioned,
|
||||
const nsID& aOperationID);
|
||||
|
||||
// Returns true if a cookie notification has been generated while completing
|
||||
// the operation.
|
||||
bool DeleteRequestOnMainThread(ThreadsafeContentParentHandle* aParent,
|
||||
const nsAString& aDomain,
|
||||
const OriginAttributes& aOriginAttributes,
|
||||
const nsAString& aName, const nsAString& aPath,
|
||||
bool aPartitioned, const nsID& aOperationID);
|
||||
bool DeleteRequestOnMainThread(
|
||||
ThreadsafeContentParentHandle* aParent, const nsAString& aDomain,
|
||||
const OriginAttributes& aOriginAttributes, bool aThirdPartyContext,
|
||||
bool aPartitionForeign, bool aUsingStorageAccess, const nsAString& aName,
|
||||
const nsAString& aPath, bool aPartitioned, const nsID& aOperationID);
|
||||
|
||||
CookieStoreNotificationWatcher* GetOrCreateNotificationWatcherOnMainThread(
|
||||
const OriginAttributes& aOriginAttributes);
|
||||
|
||||
@@ -32,6 +32,10 @@ protocol PCookieStore
|
||||
parent:
|
||||
async GetRequest(nsString domain,
|
||||
OriginAttributes attrs,
|
||||
OriginAttributes? partitionedAttrs,
|
||||
bool thirdPartyContext,
|
||||
bool partitionForeign,
|
||||
bool usingStorageAccess,
|
||||
bool matchName,
|
||||
nsString name,
|
||||
nsCString path,
|
||||
@@ -39,6 +43,9 @@ parent:
|
||||
|
||||
async SetRequest(nsString domain,
|
||||
OriginAttributes attrs,
|
||||
bool thirdPartyContext,
|
||||
bool partitionForeign,
|
||||
bool usingStorageAccess,
|
||||
nsString name,
|
||||
nsString value,
|
||||
bool session,
|
||||
@@ -50,6 +57,9 @@ parent:
|
||||
|
||||
async DeleteRequest(nsString domain,
|
||||
OriginAttributes attrs,
|
||||
bool thirdPartyContext,
|
||||
bool partitionForeign,
|
||||
bool usingStorageAccess,
|
||||
nsString name,
|
||||
nsString path,
|
||||
bool partitioned,
|
||||
|
||||
@@ -508,30 +508,41 @@ already_AddRefed<nsICookieJarSettings> CookieCommons::GetCookieJarSettings(
|
||||
}
|
||||
|
||||
// static
|
||||
bool CookieCommons::ShouldIncludeCrossSiteCookieForDocument(
|
||||
Cookie* aCookie, dom::Document* aDocument) {
|
||||
bool CookieCommons::ShouldIncludeCrossSiteCookie(Cookie* aCookie,
|
||||
bool aPartitionForeign,
|
||||
bool aInPrivateBrowsing,
|
||||
bool aUsingStorageAccess) {
|
||||
MOZ_ASSERT(aCookie);
|
||||
MOZ_ASSERT(aDocument);
|
||||
|
||||
int32_t sameSiteAttr = 0;
|
||||
aCookie->GetSameSite(&sameSiteAttr);
|
||||
|
||||
return ShouldIncludeCrossSiteCookie(
|
||||
sameSiteAttr, aCookie->IsPartitioned() && aCookie->RawIsPartitioned(),
|
||||
aPartitionForeign, aInPrivateBrowsing, aUsingStorageAccess);
|
||||
}
|
||||
|
||||
// static
|
||||
bool CookieCommons::ShouldIncludeCrossSiteCookie(int32_t aSameSiteAttr,
|
||||
bool aCookiePartitioned,
|
||||
bool aPartitionForeign,
|
||||
bool aInPrivateBrowsing,
|
||||
bool aUsingStorageAccess) {
|
||||
// CHIPS - If a third-party has storage access it can access both it's
|
||||
// partitioned and unpartitioned cookie jars, else its cookies are blocked.
|
||||
//
|
||||
// Note that we will only include partitioned cookies that have "partitioned"
|
||||
// attribution if we enable opt-in partitioning.
|
||||
if (aDocument->CookieJarSettings()->GetPartitionForeign() &&
|
||||
if (aPartitionForeign &&
|
||||
(StaticPrefs::network_cookie_cookieBehavior_optInPartitioning() ||
|
||||
(aDocument->IsInPrivateBrowsing() &&
|
||||
(aInPrivateBrowsing &&
|
||||
StaticPrefs::
|
||||
network_cookie_cookieBehavior_optInPartitioning_pbmode())) &&
|
||||
!(aCookie->IsPartitioned() && aCookie->RawIsPartitioned()) &&
|
||||
!aDocument->UsingStorageAccess()) {
|
||||
!aCookiePartitioned && !aUsingStorageAccess) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return sameSiteAttr == nsICookie::SAMESITE_NONE;
|
||||
return aSameSiteAttr == nsICookie::SAMESITE_NONE;
|
||||
}
|
||||
|
||||
bool CookieCommons::IsSafeTopLevelNav(nsIChannel* aChannel) {
|
||||
|
||||
@@ -115,8 +115,16 @@ class CookieCommons final {
|
||||
static already_AddRefed<nsICookieJarSettings> GetCookieJarSettings(
|
||||
nsIChannel* aChannel);
|
||||
|
||||
static bool ShouldIncludeCrossSiteCookieForDocument(Cookie* aCookie,
|
||||
dom::Document* aDocument);
|
||||
static bool ShouldIncludeCrossSiteCookie(Cookie* aCookie,
|
||||
bool aPartitionForeign,
|
||||
bool aInPrivateBrowsing,
|
||||
bool aUsingStorageAccess);
|
||||
|
||||
static bool ShouldIncludeCrossSiteCookie(int32_t aSameSiteAttr,
|
||||
bool aCookiePartitioned,
|
||||
bool aPartitionForeign,
|
||||
bool aInPrivateBrowsing,
|
||||
bool aUsingStorageAccess);
|
||||
|
||||
static bool IsSchemeSupported(nsIPrincipal* aPrincipal);
|
||||
static bool IsSchemeSupported(nsIURI* aURI);
|
||||
|
||||
Reference in new issue
Block a user