Bug 1551729 - Revert bug 1548432 - Re-introducing the support for cookies without values, r=mayhemer

This patch reverts the second part of bug 1548432.

Differential Revision: https://phabricator.services.mozilla.com/D31267

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrea Marchesini 2019-05-22 06:31:22 +00:00
parent 2dc620b799
commit 7b8a38ee05
12 changed files with 71 additions and 36 deletions

View File

@ -183,8 +183,8 @@ async function assignCookiesUnderFirstParty(aURL, aFirstParty, aCookieValue) {
async function generateCookies(aThirdParty) {
// we generate two different cookies for two first party domains.
let cookies = [];
cookies.push(Math.random().toString() + "=1");
cookies.push(Math.random().toString() + "=1");
cookies.push(Math.random().toString());
cookies.push(Math.random().toString());
let firstSiteURL;
let secondSiteURL;

View File

@ -128,8 +128,8 @@ function waitOnFaviconLoaded(aFaviconURL) {
async function generateCookies(aHost) {
// we generate two different cookies for two userContextIds.
let cookies = [];
cookies.push(Math.random().toString() + "=1");
cookies.push(Math.random().toString() + "=1");
cookies.push(Math.random().toString());
cookies.push(Math.random().toString());
// Then, we add cookies into the site for 'personal' and 'work'.
let tabInfoA = await openTabInUserContext(aHost, USER_CONTEXT_ID_PERSONAL);

View File

@ -189,8 +189,8 @@ add_task(async function test_favicon_privateBrowsing() {
// Generate two random cookies for non-private window and private window
// respectively.
let cookies = [];
cookies.push(Math.random().toString() + "=1");
cookies.push(Math.random().toString() + "=1");
cookies.push(Math.random().toString());
cookies.push(Math.random().toString());
// Open a tab in private window and add a cookie into it.
await assignCookies(privateWindow.gBrowser, TEST_SITE, cookies[0]);

View File

@ -114,7 +114,7 @@ add_task(async function test() {
for (let userContextId of Object.keys(USER_CONTEXTS)) {
// Load the page in 3 different contexts and set a cookie
// which should only be visible in that context.
let cookie = USER_CONTEXTS[userContextId] + "=1";
let cookie = USER_CONTEXTS[userContextId];
// Open our tab in the given user context.
let { tab, browser } = await openTabInUserContext(userContextId);

View File

@ -5,11 +5,11 @@ file_browserElement_CookiesNotThirdParty.html
<script type='text/javascript'>
if (location.search != "?step=2") {
// Step 1: Set a cookie.
document.cookie = "file_browserElement_CookiesNotThirdParty=1";
document.cookie = "file_browserElement_CookiesNotThirdParty";
alert("next");
} else {
// Step 2: Read the cookie.
if (document.cookie == "file_browserElement_CookiesNotThirdParty=1") {
if (document.cookie == "file_browserElement_CookiesNotThirdParty") {
alert("success: got the correct cookie");
} else {
alert('failure: got unexpected cookie: "' + document.cookie + '"');

View File

@ -3239,8 +3239,7 @@ bool nsCookieService::CanSetCookie(nsIURI* aHostURI, const nsCookieKey& aKey,
// newCookie says whether there are multiple cookies in the header;
// so we can handle them separately.
bool discard = false;
bool newCookie = ParseAttributes(aCookieHeader, aCookieAttributes, discard);
bool newCookie = ParseAttributes(aCookieHeader, aCookieAttributes);
// Collect telemetry on how often secure cookies are set from non-secure
// origins, and vice-versa.
@ -3386,7 +3385,7 @@ bool nsCookieService::CanSetCookie(nsIURI* aHostURI, const nsCookieKey& aKey,
}
}
aSetCookie = !discard;
aSetCookie = true;
return newCookie;
}
@ -3787,8 +3786,7 @@ bool nsCookieService::GetTokenValue(nsACString::const_char_iterator& aIter,
// folded into the cookie struct here, because we don't know which one to use
// until we've parsed the header.
bool nsCookieService::ParseAttributes(nsDependentCString& aCookieHeader,
nsCookieAttributes& aCookieAttributes,
bool& aDiscard) {
nsCookieAttributes& aCookieAttributes) {
static const char kPath[] = "path";
static const char kDomain[] = "domain";
static const char kExpires[] = "expires";
@ -3808,8 +3806,6 @@ bool nsCookieService::ParseAttributes(nsDependentCString& aCookieHeader,
aCookieAttributes.isHttpOnly = false;
aCookieAttributes.sameSite = nsICookie2::SAMESITE_UNSET;
aDiscard = false;
nsDependentCSubstring tokenString(cookieStart, cookieStart);
nsDependentCSubstring tokenValue(cookieStart, cookieStart);
bool newCookie, equalsFound;
@ -3824,11 +3820,8 @@ bool nsCookieService::ParseAttributes(nsDependentCString& aCookieHeader,
if (equalsFound) {
aCookieAttributes.name = tokenString;
aCookieAttributes.value = tokenValue;
if (aCookieAttributes.name.IsEmpty()) {
aDiscard = true;
}
} else {
aDiscard = true;
aCookieAttributes.value = tokenString;
}
// extract remaining attributes
@ -3836,10 +3829,6 @@ bool nsCookieService::ParseAttributes(nsDependentCString& aCookieHeader,
newCookie = GetTokenValue(cookieStart, cookieEnd, tokenString, tokenValue,
equalsFound);
if (aDiscard) {
continue;
}
if (!tokenValue.IsEmpty()) {
tokenValue.BeginReading(tempBegin);
tokenValue.EndReading(tempEnd);

View File

@ -341,8 +341,7 @@ class nsCookieService final : public nsICookieService,
nsDependentCSubstring& aTokenValue,
bool& aEqualsFound);
static bool ParseAttributes(nsDependentCString& aCookieHeader,
nsCookieAttributes& aCookieAttributes,
bool& aDiscard);
nsCookieAttributes& aCookie);
bool RequireThirdPartyCheck();
static bool CheckDomain(nsCookieAttributes& aCookie, nsIURI* aHostURI,
const nsCString& aBaseDomain, bool aRequireHostMatch);

View File

@ -620,7 +620,7 @@ TEST(TestCookie, TestCookieMain)
nullptr);
GetACookie(cookieService, "http://parser.test/", nullptr, cookie);
EXPECT_TRUE(CheckResult(cookie.get(), MUST_CONTAIN, R"(test="fubar! = foo)"));
EXPECT_TRUE(CheckResult(cookie.get(), MUST_NOT_CONTAIN, "five"));
EXPECT_TRUE(CheckResult(cookie.get(), MUST_CONTAIN, "five"));
SetACookie(cookieService, "http://parser.test/", nullptr,
"test=kill; domain=.parser.test; max-age=0 \n five; max-age=0",
nullptr);
@ -632,13 +632,13 @@ TEST(TestCookie, TestCookieMain)
// cookies to overwrite it
SetACookie(cookieService, "http://parser.test/", nullptr, "six", nullptr);
GetACookie(cookieService, "http://parser.test/", nullptr, cookie);
EXPECT_TRUE(CheckResult(cookie.get(), MUST_BE_NULL));
EXPECT_TRUE(CheckResult(cookie.get(), MUST_EQUAL, "six"));
SetACookie(cookieService, "http://parser.test/", nullptr, "seven", nullptr);
GetACookie(cookieService, "http://parser.test/", nullptr, cookie);
EXPECT_TRUE(CheckResult(cookie.get(), MUST_BE_NULL));
EXPECT_TRUE(CheckResult(cookie.get(), MUST_EQUAL, "seven"));
SetACookie(cookieService, "http://parser.test/", nullptr, " =eight", nullptr);
GetACookie(cookieService, "http://parser.test/", nullptr, cookie);
EXPECT_TRUE(CheckResult(cookie.get(), MUST_BE_NULL));
EXPECT_TRUE(CheckResult(cookie.get(), MUST_EQUAL, "eight"));
SetACookie(cookieService, "http://parser.test/", nullptr, "test=six",
nullptr);
GetACookie(cookieService, "http://parser.test/", nullptr, cookie);

View File

@ -1,7 +1,19 @@
[chromium-tests.html]
[chromium0009 - chromium0009]
expected: FAIL
[chromium0006 - chromium0006]
expected: FAIL
[chromium0012 - chromium0012]
expected: FAIL
[disabled-chromium0022 - disabled-chromium0022]
expected: FAIL
[chromium0010 - chromium0010]
expected: FAIL
[chromium0007 - chromium0007]
expected: FAIL

View File

@ -1,4 +1,18 @@
[general-tests.html]
[0021 - Ignore cookie without key in all 'Set-Cookie'.]
expected: FAIL
[0023 - Ignore cookies without '=' in all 'Set-Cookie'.]
expected: FAIL
[0026 - Ignore malformed cookies in all 'Set-Cookie' v2.]
expected: FAIL
[0027 - Ignore malformed cookies in all 'Set-Cookie' v3.]
expected: FAIL
[0028 - [INVALID EXPECTATION\] Ignore malformed cookies in all 'Set-Cookie' v4.]
expected: FAIL
[0004 - Ignore cookie without key.]
expected: FAIL

View File

@ -0,0 +1,21 @@
[name-tests.html]
[name0025 - name0025]
expected: FAIL
[name0023 - name0023]
expected: FAIL
[name0032 - name0032]
expected: FAIL
[name0031 - name0031]
expected: FAIL
[name0033 - name0033]
expected: FAIL
[name0028 - name0028]
expected: FAIL
[name0017 - name0017]
expected: FAIL

View File

@ -19,13 +19,13 @@ function handleRequest(req, resp) {
let setCookieScript = "";
if (opts.setRedCookie) {
resp.setHeader("Set-Cookie", "red=1", false);
setCookieScript = '<script>document.cookie="red=1";</script>';
resp.setHeader("Set-Cookie", "red", false);
setCookieScript = '<script>document.cookie="red";</script>';
}
if (opts.setGreenCookie) {
resp.setHeader("Set-Cookie", "green=1", false);
setCookieScript = '<script>document.cookie="green=1";</script>';
resp.setHeader("Set-Cookie", "green", false);
setCookieScript = '<script>document.cookie="green";</script>';
}
if (opts.iframe) {
@ -43,14 +43,14 @@ function handleRequest(req, resp) {
}
if (req.hasHeader("Cookie") &&
req.getHeader("Cookie").split(";").indexOf("red=1") >= 0) {
req.getHeader("Cookie").split(";").indexOf("red") >= 0) {
resp.write('<html style="background: #f00;">' + setCookieScript + '</html>');
resp.finish();
return;
}
if (req.hasHeader("Cookie") &&
req.getHeader("Cookie").split(";").indexOf("green=1") >= 0) {
req.getHeader("Cookie").split(";").indexOf("green") >= 0) {
resp.write('<html style="background: #0f0;">' + setCookieScript + '</html>');
resp.finish();
return;