mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 07:13:20 +00:00
Bug 1632187 - Introduce nsICookieService::setCookieStringFromDocument - part 4 - remove nsICookieService::setCookieString, r=mayhemer
Differential Revision: https://phabricator.services.mozilla.com/D71977
This commit is contained in:
parent
3321630999
commit
b5a4c16dc8
@ -409,14 +409,6 @@ already_AddRefed<nsICookieJarSettings> CookieService::GetCookieJarSettings(
|
||||
return cookieJarSettings.forget();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CookieService::SetCookieString(nsIURI* aHostURI,
|
||||
const nsACString& aCookieHeader,
|
||||
nsIChannel* aChannel) {
|
||||
NS_ENSURE_ARG(aHostURI);
|
||||
return SetCookieStringCommon(aHostURI, aCookieHeader, aChannel, false);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CookieService::SetCookieStringFromDocument(Document* aDocument,
|
||||
const nsACString& aCookieString) {
|
||||
@ -460,48 +452,18 @@ CookieService::SetCookieStringFromHttp(nsIURI* aHostURI,
|
||||
nsIChannel* aChannel) {
|
||||
NS_ENSURE_ARG(aHostURI);
|
||||
NS_ENSURE_ARG(aChannel);
|
||||
return SetCookieStringCommon(aHostURI, aCookieHeader, aChannel, true);
|
||||
}
|
||||
|
||||
nsresult CookieService::SetCookieStringCommon(nsIURI* aHostURI,
|
||||
const nsACString& aCookieHeader,
|
||||
nsIChannel* aChannel,
|
||||
bool aFromHttp) {
|
||||
MOZ_ASSERT(aHostURI);
|
||||
if (!IsInitialized()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
uint32_t rejectedReason = 0;
|
||||
ThirdPartyAnalysisResult result = mThirdPartyUtil->AnalyzeChannel(
|
||||
aChannel, false, aHostURI, nullptr, &rejectedReason);
|
||||
|
||||
OriginAttributes attrs;
|
||||
if (aChannel) {
|
||||
StoragePrincipalHelper::GetOriginAttributes(
|
||||
aChannel, attrs, StoragePrincipalHelper::eStorageAccessPrincipal);
|
||||
}
|
||||
|
||||
nsCString cookieString(aCookieHeader);
|
||||
SetCookieStringInternal(
|
||||
aHostURI, result.contains(ThirdPartyAnalysis::IsForeign),
|
||||
result.contains(ThirdPartyAnalysis::IsThirdPartyTrackingResource),
|
||||
result.contains(ThirdPartyAnalysis::IsThirdPartySocialTrackingResource),
|
||||
result.contains(ThirdPartyAnalysis::IsFirstPartyStorageAccessGranted),
|
||||
rejectedReason, cookieString, aFromHttp, attrs, aChannel);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void CookieService::SetCookieStringInternal(
|
||||
nsIURI* aHostURI, bool aIsForeign, bool aIsThirdPartyTrackingResource,
|
||||
bool aIsThirdPartySocialTrackingResource,
|
||||
bool aFirstPartyStorageAccessGranted, uint32_t aRejectedReason,
|
||||
nsCString& aCookieHeader, bool aFromHttp,
|
||||
const OriginAttributes& aOriginAttrs, nsIChannel* aChannel) {
|
||||
NS_ASSERTION(aHostURI, "null host!");
|
||||
|
||||
if (!IsInitialized()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CookieStorage* storage = PickStorage(aOriginAttrs);
|
||||
StoragePrincipalHelper::GetOriginAttributes(
|
||||
aChannel, attrs, StoragePrincipalHelper::eStorageAccessPrincipal);
|
||||
|
||||
// get the base domain for the host URI.
|
||||
// e.g. for "www.bbc.co.uk", this would be "bbc.co.uk".
|
||||
@ -515,7 +477,7 @@ void CookieService::SetCookieStringInternal(
|
||||
if (NS_FAILED(rv)) {
|
||||
COOKIE_LOGFAILURE(SET_COOKIE, aHostURI, aCookieHeader,
|
||||
"couldn't get base domain from URI");
|
||||
return;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsICookieJarSettings> cookieJarSettings =
|
||||
@ -524,22 +486,26 @@ void CookieService::SetCookieStringInternal(
|
||||
nsAutoCString hostFromURI;
|
||||
aHostURI->GetHost(hostFromURI);
|
||||
rv = NormalizeHost(hostFromURI);
|
||||
NS_ENSURE_SUCCESS_VOID(rv);
|
||||
NS_ENSURE_SUCCESS(rv, NS_OK);
|
||||
|
||||
nsAutoCString baseDomainFromURI;
|
||||
rv = CookieCommons::GetBaseDomainFromHost(mTLDService, hostFromURI,
|
||||
baseDomainFromURI);
|
||||
NS_ENSURE_SUCCESS_VOID(rv);
|
||||
NS_ENSURE_SUCCESS(rv, NS_OK);
|
||||
|
||||
CookieStorage* storage = PickStorage(attrs);
|
||||
|
||||
// check default prefs
|
||||
uint32_t priorCookieCount = storage->CountCookiesFromHost(
|
||||
baseDomainFromURI, aOriginAttrs.mPrivateBrowsingId);
|
||||
uint32_t rejectedReason = aRejectedReason;
|
||||
baseDomainFromURI, attrs.mPrivateBrowsingId);
|
||||
|
||||
CookieStatus cookieStatus = CheckPrefs(
|
||||
cookieJarSettings, aHostURI, aIsForeign, aIsThirdPartyTrackingResource,
|
||||
aIsThirdPartySocialTrackingResource, aFirstPartyStorageAccessGranted,
|
||||
aCookieHeader, priorCookieCount, aOriginAttrs, &rejectedReason);
|
||||
cookieJarSettings, aHostURI,
|
||||
result.contains(ThirdPartyAnalysis::IsForeign),
|
||||
result.contains(ThirdPartyAnalysis::IsThirdPartyTrackingResource),
|
||||
result.contains(ThirdPartyAnalysis::IsThirdPartySocialTrackingResource),
|
||||
result.contains(ThirdPartyAnalysis::IsFirstPartyStorageAccessGranted),
|
||||
aCookieHeader, priorCookieCount, attrs, &rejectedReason);
|
||||
|
||||
MOZ_ASSERT_IF(rejectedReason, cookieStatus == STATUS_REJECTED);
|
||||
|
||||
@ -549,11 +515,11 @@ void CookieService::SetCookieStringInternal(
|
||||
case STATUS_REJECTED:
|
||||
CookieCommons::NotifyRejected(aHostURI, aChannel, rejectedReason,
|
||||
OPERATION_WRITE);
|
||||
return; // Stop here
|
||||
return NS_OK; // Stop here
|
||||
case STATUS_REJECTED_WITH_ERROR:
|
||||
CookieCommons::NotifyRejected(aHostURI, aChannel, rejectedReason,
|
||||
OPERATION_WRITE);
|
||||
return;
|
||||
return NS_OK;
|
||||
case STATUS_ACCEPTED: // Fallthrough
|
||||
case STATUS_ACCEPT_SESSION:
|
||||
NotifyAccepted(aChannel);
|
||||
@ -562,15 +528,64 @@ void CookieService::SetCookieStringInternal(
|
||||
break;
|
||||
}
|
||||
|
||||
// process each cookie in the header
|
||||
while (SetCookieInternal(storage, aHostURI, baseDomain, aOriginAttrs,
|
||||
requireHostMatch, cookieStatus, aCookieHeader,
|
||||
aFromHttp, aChannel)) {
|
||||
// document.cookie can only set one cookie at a time
|
||||
if (!aFromHttp) {
|
||||
break;
|
||||
}
|
||||
bool addonAllowsLoad = false;
|
||||
nsCOMPtr<nsIURI> channelURI;
|
||||
NS_GetFinalChannelURI(aChannel, getter_AddRefs(channelURI));
|
||||
nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
|
||||
addonAllowsLoad = BasePrincipal::Cast(loadInfo->TriggeringPrincipal())
|
||||
->AddonAllowsLoad(channelURI);
|
||||
|
||||
bool isForeignAndNotAddon = false;
|
||||
if (!addonAllowsLoad) {
|
||||
mThirdPartyUtil->IsThirdPartyChannel(aChannel, aHostURI,
|
||||
&isForeignAndNotAddon);
|
||||
}
|
||||
|
||||
nsCString cookieHeader(aCookieHeader);
|
||||
|
||||
nsCOMPtr<nsIConsoleReportCollector> crc = do_QueryInterface(aChannel);
|
||||
|
||||
bool moreCookieToRead = true;
|
||||
|
||||
// process each cookie in the header
|
||||
while (moreCookieToRead) {
|
||||
CookieStruct cookieData;
|
||||
bool canSetCookie = false;
|
||||
|
||||
moreCookieToRead = CanSetCookie(
|
||||
aHostURI, baseDomain, cookieData, requireHostMatch, cookieStatus,
|
||||
cookieHeader, true, isForeignAndNotAddon, crc, canSetCookie);
|
||||
|
||||
if (!canSetCookie) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// check permissions from site permission list.
|
||||
if (!CookieCommons::CheckCookiePermission(aChannel, cookieData)) {
|
||||
COOKIE_LOGFAILURE(SET_COOKIE, aHostURI, aCookieHeader,
|
||||
"cookie rejected by permission manager");
|
||||
CookieCommons::NotifyRejected(
|
||||
aHostURI, aChannel,
|
||||
nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION,
|
||||
OPERATION_WRITE);
|
||||
continue;
|
||||
}
|
||||
|
||||
// create a new Cookie
|
||||
RefPtr<Cookie> cookie = Cookie::Create(cookieData, attrs);
|
||||
MOZ_ASSERT(cookie);
|
||||
|
||||
int64_t currentTimeInUsec = PR_Now();
|
||||
cookie->SetLastAccessed(currentTimeInUsec);
|
||||
cookie->SetCreationTime(
|
||||
Cookie::GenerateUniqueCreationTime(currentTimeInUsec));
|
||||
|
||||
// add the cookie to the list. AddCookie() takes care of logging.
|
||||
storage->AddCookie(baseDomain, attrs, cookie, currentTimeInUsec, aHostURI,
|
||||
aCookieHeader, true);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void CookieService::NotifyAccepted(nsIChannel* aChannel) {
|
||||
@ -1047,72 +1062,6 @@ bool CookieService::CanSetCookie(
|
||||
return newCookie;
|
||||
}
|
||||
|
||||
// processes a single cookie, and returns true if there are more cookies
|
||||
// to be processed
|
||||
bool CookieService::SetCookieInternal(CookieStorage* aStorage, nsIURI* aHostURI,
|
||||
const nsACString& aBaseDomain,
|
||||
const OriginAttributes& aOriginAttributes,
|
||||
bool aRequireHostMatch,
|
||||
CookieStatus aStatus,
|
||||
nsCString& aCookieHeader, bool aFromHttp,
|
||||
nsIChannel* aChannel) {
|
||||
NS_ASSERTION(aHostURI, "null host!");
|
||||
nsCString savedCookieHeader(aCookieHeader);
|
||||
|
||||
bool addonAllowsLoad = false;
|
||||
if (aChannel) {
|
||||
nsCOMPtr<nsIURI> channelURI;
|
||||
NS_GetFinalChannelURI(aChannel, getter_AddRefs(channelURI));
|
||||
nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
|
||||
addonAllowsLoad = BasePrincipal::Cast(loadInfo->TriggeringPrincipal())
|
||||
->AddonAllowsLoad(channelURI);
|
||||
}
|
||||
|
||||
bool isForeignAndNotAddon = false;
|
||||
if (!addonAllowsLoad) {
|
||||
mThirdPartyUtil->IsThirdPartyChannel(aChannel, aHostURI,
|
||||
&isForeignAndNotAddon);
|
||||
}
|
||||
|
||||
CookieStruct cookieData;
|
||||
bool canSetCookie = false;
|
||||
|
||||
nsCOMPtr<nsIConsoleReportCollector> crc = do_QueryInterface(aChannel);
|
||||
|
||||
bool newCookie = CanSetCookie(
|
||||
aHostURI, aBaseDomain, cookieData, aRequireHostMatch, aStatus,
|
||||
aCookieHeader, aFromHttp, isForeignAndNotAddon, crc, canSetCookie);
|
||||
|
||||
if (!canSetCookie) {
|
||||
return newCookie;
|
||||
}
|
||||
|
||||
// check permissions from site permission list.
|
||||
if (!CookieCommons::CheckCookiePermission(aChannel, cookieData)) {
|
||||
COOKIE_LOGFAILURE(SET_COOKIE, aHostURI, savedCookieHeader,
|
||||
"cookie rejected by permission manager");
|
||||
CookieCommons::NotifyRejected(
|
||||
aHostURI, aChannel,
|
||||
nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION,
|
||||
OPERATION_WRITE);
|
||||
return newCookie;
|
||||
}
|
||||
|
||||
// create a new Cookie
|
||||
RefPtr<Cookie> cookie = Cookie::Create(cookieData, aOriginAttributes);
|
||||
MOZ_ASSERT(cookie);
|
||||
|
||||
int64_t currentTimeInUsec = PR_Now();
|
||||
cookie->SetLastAccessed(currentTimeInUsec);
|
||||
cookie->SetCreationTime(
|
||||
Cookie::GenerateUniqueCreationTime(currentTimeInUsec));
|
||||
|
||||
// add the cookie to the list. AddCookie() takes care of logging.
|
||||
aStorage->AddCookie(aBaseDomain, aOriginAttributes, cookie, currentTimeInUsec,
|
||||
aHostURI, savedCookieHeader, aFromHttp);
|
||||
return newCookie;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* CookieService impl:
|
||||
* private cookie header parsing functions
|
||||
|
@ -115,23 +115,6 @@ class CookieService final : public nsICookieService,
|
||||
|
||||
void EnsureReadComplete(bool aInitDBConn);
|
||||
nsresult NormalizeHost(nsCString& aHost);
|
||||
nsresult SetCookieStringCommon(nsIURI* aHostURI,
|
||||
const nsACString& aCookieHeader,
|
||||
nsIChannel* aChannel, bool aFromHttp);
|
||||
void SetCookieStringInternal(nsIURI* aHostURI, bool aIsForeign,
|
||||
bool aIsThirdPartyTrackingResource,
|
||||
bool aIsThirdPartySocialTrackingResource,
|
||||
bool aFirstPartyStorageAccessGranted,
|
||||
uint32_t aRejectedReason,
|
||||
nsCString& aCookieHeader, bool aFromHttp,
|
||||
const OriginAttributes& aOriginAttrs,
|
||||
nsIChannel* aChannel);
|
||||
bool SetCookieInternal(CookieStorage* aStorage, nsIURI* aHostURI,
|
||||
const nsACString& aBaseDomain,
|
||||
const OriginAttributes& aOriginAttributes,
|
||||
bool aRequireHostMatch, CookieStatus aStatus,
|
||||
nsCString& aCookieHeader, bool aFromHttp,
|
||||
nsIChannel* aChannel);
|
||||
static bool GetTokenValue(nsACString::const_char_iterator& aIter,
|
||||
nsACString::const_char_iterator& aEndIter,
|
||||
nsDependentCSubstring& aTokenString,
|
||||
|
@ -134,6 +134,7 @@ void CookieServiceChild::TrackCookieLoad(nsIChannel* aChannel) {
|
||||
OriginAttributes attrs = loadInfo->GetOriginAttributes();
|
||||
StoragePrincipalHelper::PrepareEffectiveStoragePrincipalOriginAttributes(
|
||||
aChannel, attrs);
|
||||
|
||||
bool isSafeTopLevelNav = NS_IsSafeTopLevelNav(aChannel);
|
||||
bool isSameSiteForeign = NS_IsSameSiteForeign(aChannel, uri);
|
||||
SendPrepareCookieList(
|
||||
@ -296,147 +297,6 @@ void CookieServiceChild::RecordDocumentCookie(Cookie* aCookie,
|
||||
cookiesList->AppendElement(aCookie);
|
||||
}
|
||||
|
||||
nsresult CookieServiceChild::SetCookieStringInternal(
|
||||
nsIURI* aHostURI, nsIChannel* aChannel, const nsACString& aCookieString,
|
||||
bool aFromHttp) {
|
||||
MOZ_ASSERT(aHostURI);
|
||||
|
||||
// Fast past: don't bother sending IPC messages about nullprincipal'd
|
||||
// documents.
|
||||
nsAutoCString scheme;
|
||||
aHostURI->GetScheme(scheme);
|
||||
if (scheme.EqualsLiteral("moz-nullprincipal")) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsILoadInfo> loadInfo = aChannel ? aChannel->LoadInfo() : nullptr;
|
||||
|
||||
uint32_t rejectedReason = 0;
|
||||
ThirdPartyAnalysisResult result = mThirdPartyUtil->AnalyzeChannel(
|
||||
aChannel, false, aHostURI, RequireThirdPartyCheck, &rejectedReason);
|
||||
|
||||
nsCString cookieString(aCookieString);
|
||||
|
||||
nsCOMPtr<nsIURI> channelURI;
|
||||
OriginAttributes attrs;
|
||||
if (aChannel) {
|
||||
aChannel->GetURI(getter_AddRefs(channelURI));
|
||||
|
||||
MOZ_ASSERT(loadInfo);
|
||||
attrs = loadInfo->GetOriginAttributes();
|
||||
StoragePrincipalHelper::PrepareEffectiveStoragePrincipalOriginAttributes(
|
||||
aChannel, attrs);
|
||||
}
|
||||
|
||||
Maybe<LoadInfoArgs> optionalLoadInfoArgs;
|
||||
LoadInfoToLoadInfoArgs(loadInfo, &optionalLoadInfoArgs);
|
||||
|
||||
bool requireHostMatch;
|
||||
nsCString baseDomain;
|
||||
CookieCommons::GetBaseDomain(mTLDService, aHostURI, baseDomain,
|
||||
requireHostMatch);
|
||||
|
||||
nsCOMPtr<nsICookieJarSettings> cookieJarSettings =
|
||||
CookieService::GetCookieJarSettings(aChannel);
|
||||
|
||||
CookieStatus cookieStatus = CookieService::CheckPrefs(
|
||||
cookieJarSettings, aHostURI,
|
||||
result.contains(ThirdPartyAnalysis::IsForeign),
|
||||
result.contains(ThirdPartyAnalysis::IsThirdPartyTrackingResource),
|
||||
result.contains(ThirdPartyAnalysis::IsThirdPartySocialTrackingResource),
|
||||
result.contains(ThirdPartyAnalysis::IsFirstPartyStorageAccessGranted),
|
||||
aCookieString, CountCookiesFromHashTable(baseDomain, attrs), attrs,
|
||||
&rejectedReason);
|
||||
|
||||
if (cookieStatus != STATUS_ACCEPTED &&
|
||||
cookieStatus != STATUS_ACCEPT_SESSION) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
CookieKey key(baseDomain, attrs);
|
||||
CookiesList* cookies = mCookiesMap.Get(key);
|
||||
|
||||
nsTArray<CookieStruct> cookiesToSend;
|
||||
|
||||
int64_t currentTimeInUsec = PR_Now();
|
||||
|
||||
bool addonAllowsLoad = false;
|
||||
if (aChannel) {
|
||||
nsCOMPtr<nsIURI> channelURI;
|
||||
NS_GetFinalChannelURI(aChannel, getter_AddRefs(channelURI));
|
||||
nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
|
||||
addonAllowsLoad = BasePrincipal::Cast(loadInfo->TriggeringPrincipal())
|
||||
->AddonAllowsLoad(channelURI);
|
||||
}
|
||||
|
||||
bool isForeignAndNotAddon = false;
|
||||
if (!addonAllowsLoad) {
|
||||
mThirdPartyUtil->IsThirdPartyChannel(aChannel, aHostURI,
|
||||
&isForeignAndNotAddon);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIConsoleReportCollector> crc = do_QueryInterface(aChannel);
|
||||
|
||||
bool moreCookies;
|
||||
do {
|
||||
CookieStruct cookieData;
|
||||
bool canSetCookie = false;
|
||||
moreCookies = CookieService::CanSetCookie(
|
||||
aHostURI, baseDomain, cookieData, requireHostMatch, cookieStatus,
|
||||
cookieString, aFromHttp, isForeignAndNotAddon, crc, canSetCookie);
|
||||
|
||||
// We need to see if the cookie we're setting would overwrite an httponly
|
||||
// one. This would not affect anything we send over the net (those come from
|
||||
// the parent, which already checks this), but script could see an
|
||||
// inconsistent view of things.
|
||||
if (cookies && canSetCookie && !aFromHttp) {
|
||||
for (uint32_t i = 0; i < cookies->Length(); ++i) {
|
||||
RefPtr<Cookie> cookie = cookies->ElementAt(i);
|
||||
if (cookie->Name().Equals(cookieData.name()) &&
|
||||
cookie->Host().Equals(cookieData.host()) &&
|
||||
cookie->Path().Equals(cookieData.path()) && cookie->IsHttpOnly()) {
|
||||
// Can't overwrite an httponly cookie from a script context.
|
||||
canSetCookie = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!canSetCookie) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// check permissions from site permission list.
|
||||
if (!CookieCommons::CheckCookiePermission(aChannel, cookieData)) {
|
||||
COOKIE_LOGFAILURE(SET_COOKIE, aHostURI, aCookieString,
|
||||
"cookie rejected by permission manager");
|
||||
CookieCommons::NotifyRejected(
|
||||
aHostURI, aChannel,
|
||||
nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION,
|
||||
OPERATION_WRITE);
|
||||
continue;
|
||||
}
|
||||
|
||||
RefPtr<Cookie> cookie = Cookie::Create(cookieData, attrs);
|
||||
MOZ_ASSERT(cookie);
|
||||
|
||||
cookie->SetLastAccessed(currentTimeInUsec);
|
||||
cookie->SetCreationTime(
|
||||
Cookie::GenerateUniqueCreationTime(currentTimeInUsec));
|
||||
|
||||
RecordDocumentCookie(cookie, attrs);
|
||||
cookiesToSend.AppendElement(cookieData);
|
||||
|
||||
// document.cookie can only set one cookie at a time.
|
||||
} while (moreCookies && aFromHttp);
|
||||
|
||||
// Asynchronously call the parent.
|
||||
if (CanSend() && !cookiesToSend.IsEmpty()) {
|
||||
SendSetCookies(baseDomain, attrs, aHostURI, aFromHttp, cookiesToSend);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CookieServiceChild::Observe(nsISupports* aSubject, const char* aTopic,
|
||||
const char16_t* /*aData*/) {
|
||||
@ -546,14 +406,6 @@ CookieServiceChild::GetCookieStringFromHttp(nsIURI* /*aHostURI*/,
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CookieServiceChild::SetCookieString(nsIURI* aHostURI,
|
||||
const nsACString& aCookieString,
|
||||
nsIChannel* aChannel) {
|
||||
NS_ENSURE_ARG(aHostURI);
|
||||
return SetCookieStringInternal(aHostURI, aChannel, aCookieString, false);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CookieServiceChild::SetCookieStringFromDocument(
|
||||
Document* aDocument, const nsACString& aCookieString) {
|
||||
@ -616,7 +468,108 @@ CookieServiceChild::SetCookieStringFromHttp(nsIURI* aHostURI,
|
||||
nsIChannel* aChannel) {
|
||||
NS_ENSURE_ARG(aHostURI);
|
||||
NS_ENSURE_ARG(aChannel);
|
||||
return SetCookieStringInternal(aHostURI, aChannel, aCookieString, true);
|
||||
|
||||
// Fast past: don't bother sending IPC messages about nullprincipal'd
|
||||
// documents.
|
||||
nsAutoCString scheme;
|
||||
aHostURI->GetScheme(scheme);
|
||||
if (scheme.EqualsLiteral("moz-nullprincipal")) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
|
||||
|
||||
uint32_t rejectedReason = 0;
|
||||
ThirdPartyAnalysisResult result = mThirdPartyUtil->AnalyzeChannel(
|
||||
aChannel, false, aHostURI, RequireThirdPartyCheck, &rejectedReason);
|
||||
|
||||
nsCString cookieString(aCookieString);
|
||||
|
||||
OriginAttributes attrs = loadInfo->GetOriginAttributes();
|
||||
StoragePrincipalHelper::PrepareEffectiveStoragePrincipalOriginAttributes(
|
||||
aChannel, attrs);
|
||||
|
||||
bool requireHostMatch;
|
||||
nsCString baseDomain;
|
||||
CookieCommons::GetBaseDomain(mTLDService, aHostURI, baseDomain,
|
||||
requireHostMatch);
|
||||
|
||||
nsCOMPtr<nsICookieJarSettings> cookieJarSettings =
|
||||
CookieService::GetCookieJarSettings(aChannel);
|
||||
|
||||
CookieStatus cookieStatus = CookieService::CheckPrefs(
|
||||
cookieJarSettings, aHostURI,
|
||||
result.contains(ThirdPartyAnalysis::IsForeign),
|
||||
result.contains(ThirdPartyAnalysis::IsThirdPartyTrackingResource),
|
||||
result.contains(ThirdPartyAnalysis::IsThirdPartySocialTrackingResource),
|
||||
result.contains(ThirdPartyAnalysis::IsFirstPartyStorageAccessGranted),
|
||||
aCookieString, CountCookiesFromHashTable(baseDomain, attrs), attrs,
|
||||
&rejectedReason);
|
||||
|
||||
if (cookieStatus != STATUS_ACCEPTED &&
|
||||
cookieStatus != STATUS_ACCEPT_SESSION) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
CookieKey key(baseDomain, attrs);
|
||||
|
||||
nsTArray<CookieStruct> cookiesToSend;
|
||||
|
||||
int64_t currentTimeInUsec = PR_Now();
|
||||
|
||||
bool addonAllowsLoad = false;
|
||||
nsCOMPtr<nsIURI> finalChannelURI;
|
||||
NS_GetFinalChannelURI(aChannel, getter_AddRefs(finalChannelURI));
|
||||
addonAllowsLoad = BasePrincipal::Cast(loadInfo->TriggeringPrincipal())
|
||||
->AddonAllowsLoad(finalChannelURI);
|
||||
|
||||
bool isForeignAndNotAddon = false;
|
||||
if (!addonAllowsLoad) {
|
||||
mThirdPartyUtil->IsThirdPartyChannel(aChannel, aHostURI,
|
||||
&isForeignAndNotAddon);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIConsoleReportCollector> crc = do_QueryInterface(aChannel);
|
||||
|
||||
bool moreCookies;
|
||||
do {
|
||||
CookieStruct cookieData;
|
||||
bool canSetCookie = false;
|
||||
moreCookies = CookieService::CanSetCookie(
|
||||
aHostURI, baseDomain, cookieData, requireHostMatch, cookieStatus,
|
||||
cookieString, true, isForeignAndNotAddon, crc, canSetCookie);
|
||||
if (!canSetCookie) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// check permissions from site permission list.
|
||||
if (!CookieCommons::CheckCookiePermission(aChannel, cookieData)) {
|
||||
COOKIE_LOGFAILURE(SET_COOKIE, aHostURI, aCookieString,
|
||||
"cookie rejected by permission manager");
|
||||
CookieCommons::NotifyRejected(
|
||||
aHostURI, aChannel,
|
||||
nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION,
|
||||
OPERATION_WRITE);
|
||||
continue;
|
||||
}
|
||||
|
||||
RefPtr<Cookie> cookie = Cookie::Create(cookieData, attrs);
|
||||
MOZ_ASSERT(cookie);
|
||||
|
||||
cookie->SetLastAccessed(currentTimeInUsec);
|
||||
cookie->SetCreationTime(
|
||||
Cookie::GenerateUniqueCreationTime(currentTimeInUsec));
|
||||
|
||||
RecordDocumentCookie(cookie, attrs);
|
||||
cookiesToSend.AppendElement(cookieData);
|
||||
} while (moreCookies);
|
||||
|
||||
// Asynchronously call the parent.
|
||||
if (CanSend() && !cookiesToSend.IsEmpty()) {
|
||||
SendSetCookies(baseDomain, attrs, aHostURI, true, cookiesToSend);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -51,10 +51,6 @@ class CookieServiceChild final : public PCookieServiceChild,
|
||||
~CookieServiceChild();
|
||||
void MoveCookies();
|
||||
|
||||
nsresult SetCookieStringInternal(nsIURI* aHostURI, nsIChannel* aChannel,
|
||||
const nsACString& aCookieString,
|
||||
bool aFromHttp);
|
||||
|
||||
void RecordDocumentCookie(Cookie* aCookie, const OriginAttributes& aAttrs);
|
||||
|
||||
uint32_t CountCookiesFromHashTable(const nsACString& aBaseDomain,
|
||||
|
@ -134,26 +134,6 @@ interface nsICookieService : nsISupports
|
||||
*/
|
||||
void setCookieStringFromDocument(in Document aDocument, in ACString aCookie);
|
||||
|
||||
/*
|
||||
* Set the cookie string associated with the URI.
|
||||
*
|
||||
* @param aURI
|
||||
* The URI of the document for which cookies are being queried.
|
||||
* file:// URIs (i.e. with an empty host) are allowed, but any other
|
||||
* scheme must have a non-empty host. A trailing dot in the host
|
||||
* is acceptable, and will be stripped. This argument must not be null.
|
||||
* @param aCookie
|
||||
* the cookie string to set.
|
||||
* @param aChannel
|
||||
* the channel used to load the document. this parameter should not
|
||||
* be null, otherwise the cookies will not be set if third-party
|
||||
* cookies have been disabled by the user. (the channel is used
|
||||
* to determine the originating URI of the document; if it is not
|
||||
* provided, the cookies will be assumed third-party.)
|
||||
*/
|
||||
void setCookieString(in nsIURI aURI, in ACString aCookie,
|
||||
in nsIChannel aChannel);
|
||||
|
||||
/*
|
||||
* Set the cookie string and expires associated with the URI.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user