Bug 1641459 - Consider 3rd parties cookie requested by documents with a window, r=smaug

This is required for how Cookies gtests are written

Differential Revision: https://phabricator.services.mozilla.com/D77301
This commit is contained in:
Andrea Marchesini 2020-05-29 15:57:29 +00:00
Родитель 948adbdc87
Коммит a0049a050f
3 изменённых файлов: 27 добавлений и 18 удалений

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

@ -317,14 +317,15 @@ CookieService::GetCookieStringFromDocument(Document* aDocument,
// if it isn't, then we can't send a secure cookie over the connection. // if it isn't, then we can't send a secure cookie over the connection.
bool potentiallyTurstworthy = principal->GetIsOriginPotentiallyTrustworthy(); bool potentiallyTurstworthy = principal->GetIsOriginPotentiallyTrustworthy();
bool thirdParty = true;
nsPIDOMWindowInner* innerWindow = aDocument->GetInnerWindow(); nsPIDOMWindowInner* innerWindow = aDocument->GetInnerWindow();
if (NS_WARN_IF(!innerWindow)) { // in gtests we don't have a window, let's consider those requests as 3rd
return NS_OK; // party.
if (innerWindow) {
thirdParty = nsContentUtils::IsThirdPartyWindowOrChannel(innerWindow,
nullptr, nullptr);
} }
bool thirdParty = nsContentUtils::IsThirdPartyWindowOrChannel(
innerWindow, nullptr, nullptr);
bool stale = false; bool stale = false;
nsTArray<Cookie*> cookieList; nsTArray<Cookie*> cookieList;
@ -455,13 +456,16 @@ CookieService::SetCookieStringFromDocument(Document* aDocument,
return NS_OK; return NS_OK;
} }
bool thirdParty = true;
nsPIDOMWindowInner* innerWindow = aDocument->GetInnerWindow(); nsPIDOMWindowInner* innerWindow = aDocument->GetInnerWindow();
if (NS_WARN_IF(!innerWindow)) { // in gtests we don't have a window, let's consider those requests as 3rd
return NS_OK; // party.
if (innerWindow) {
thirdParty = nsContentUtils::IsThirdPartyWindowOrChannel(innerWindow,
nullptr, nullptr);
} }
if (nsContentUtils::IsThirdPartyWindowOrChannel(innerWindow, nullptr, if (thirdParty &&
nullptr) &&
!CookieCommons::ShouldIncludeCrossSiteCookieForDocument(cookie)) { !CookieCommons::ShouldIncludeCrossSiteCookieForDocument(cookie)) {
return NS_OK; return NS_OK;
} }

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

@ -351,14 +351,15 @@ CookieServiceChild::GetCookieStringFromDocument(Document* aDocument,
nsAutoCString pathFromURI; nsAutoCString pathFromURI;
principal->GetFilePath(pathFromURI); principal->GetFilePath(pathFromURI);
bool thirdParty = true;
nsPIDOMWindowInner* innerWindow = aDocument->GetInnerWindow(); nsPIDOMWindowInner* innerWindow = aDocument->GetInnerWindow();
if (NS_WARN_IF(!innerWindow)) { // in gtests we don't have a window, let's consider those requests as 3rd
return NS_OK; // party.
if (innerWindow) {
thirdParty = nsContentUtils::IsThirdPartyWindowOrChannel(innerWindow,
nullptr, nullptr);
} }
bool thirdParty = nsContentUtils::IsThirdPartyWindowOrChannel(
innerWindow, nullptr, nullptr);
bool isPotentiallyTrustworthy = bool isPotentiallyTrustworthy =
principal->GetIsOriginPotentiallyTrustworthy(); principal->GetIsOriginPotentiallyTrustworthy();
int64_t currentTimeInUsec = PR_Now(); int64_t currentTimeInUsec = PR_Now();
@ -444,13 +445,16 @@ CookieServiceChild::SetCookieStringFromDocument(
return NS_OK; return NS_OK;
} }
bool thirdParty = true;
nsPIDOMWindowInner* innerWindow = aDocument->GetInnerWindow(); nsPIDOMWindowInner* innerWindow = aDocument->GetInnerWindow();
if (NS_WARN_IF(!innerWindow)) { // in gtests we don't have a window, let's consider those requests as 3rd
return NS_OK; // party.
if (innerWindow) {
thirdParty = nsContentUtils::IsThirdPartyWindowOrChannel(innerWindow,
nullptr, nullptr);
} }
if (nsContentUtils::IsThirdPartyWindowOrChannel(innerWindow, nullptr, if (thirdParty &&
nullptr) &&
!CookieCommons::ShouldIncludeCrossSiteCookieForDocument(cookie)) { !CookieCommons::ShouldIncludeCrossSiteCookieForDocument(cookie)) {
return NS_OK; return NS_OK;
} }

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

@ -1026,6 +1026,7 @@ TEST(TestCookie, SameSiteLax)
TEST(TestCookie, OnionSite) TEST(TestCookie, OnionSite)
{ {
Preferences::SetBool("dom.securecontext.whitelist_onions", true); Preferences::SetBool("dom.securecontext.whitelist_onions", true);
Preferences::SetBool("network.cookie.sameSite.laxByDefault", false);
nsresult rv; nsresult rv;
nsCString cookie; nsCString cookie;