Backed out changeset 754426d70d28 (bug 1551729) for causing wpt failures. CLOSED TREE

This commit is contained in:
Mihai Alexandru Michis 2019-05-21 15:17:37 +03:00
parent 84b1872a1c
commit 68421ffba4
11 changed files with 36 additions and 50 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());
cookies.push(Math.random().toString());
cookies.push(Math.random().toString() + "=1");
cookies.push(Math.random().toString() + "=1");
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());
cookies.push(Math.random().toString());
cookies.push(Math.random().toString() + "=1");
cookies.push(Math.random().toString() + "=1");
// 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());
cookies.push(Math.random().toString());
cookies.push(Math.random().toString() + "=1");
cookies.push(Math.random().toString() + "=1");
// 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];
let cookie = USER_CONTEXTS[userContextId] + "=1";
// 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";
document.cookie = "file_browserElement_CookiesNotThirdParty=1";
alert("next");
} else {
// Step 2: Read the cookie.
if (document.cookie == "file_browserElement_CookiesNotThirdParty") {
if (document.cookie == "file_browserElement_CookiesNotThirdParty=1") {
alert("success: got the correct cookie");
} else {
alert('failure: got unexpected cookie: "' + document.cookie + '"');

View File

@ -3239,7 +3239,8 @@ 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 newCookie = ParseAttributes(aCookieHeader, aCookieAttributes);
bool discard = false;
bool newCookie = ParseAttributes(aCookieHeader, aCookieAttributes, discard);
// Collect telemetry on how often secure cookies are set from non-secure
// origins, and vice-versa.
@ -3385,7 +3386,7 @@ bool nsCookieService::CanSetCookie(nsIURI* aHostURI, const nsCookieKey& aKey,
}
}
aSetCookie = true;
aSetCookie = !discard;
return newCookie;
}
@ -3786,7 +3787,8 @@ 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) {
nsCookieAttributes& aCookieAttributes,
bool& aDiscard) {
static const char kPath[] = "path";
static const char kDomain[] = "domain";
static const char kExpires[] = "expires";
@ -3806,6 +3808,8 @@ 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;
@ -3820,8 +3824,11 @@ bool nsCookieService::ParseAttributes(nsDependentCString& aCookieHeader,
if (equalsFound) {
aCookieAttributes.name = tokenString;
aCookieAttributes.value = tokenValue;
if (aCookieAttributes.name.IsEmpty()) {
aDiscard = true;
}
} else {
aCookieAttributes.value = tokenString;
aDiscard = true;
}
// extract remaining attributes
@ -3829,6 +3836,10 @@ 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,7 +341,8 @@ class nsCookieService final : public nsICookieService,
nsDependentCSubstring& aTokenValue,
bool& aEqualsFound);
static bool ParseAttributes(nsDependentCString& aCookieHeader,
nsCookieAttributes& aCookie);
nsCookieAttributes& aCookieAttributes,
bool& aDiscard);
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_CONTAIN, "five"));
EXPECT_TRUE(CheckResult(cookie.get(), MUST_NOT_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_EQUAL, "six"));
EXPECT_TRUE(CheckResult(cookie.get(), MUST_BE_NULL));
SetACookie(cookieService, "http://parser.test/", nullptr, "seven", nullptr);
GetACookie(cookieService, "http://parser.test/", nullptr, cookie);
EXPECT_TRUE(CheckResult(cookie.get(), MUST_EQUAL, "seven"));
EXPECT_TRUE(CheckResult(cookie.get(), MUST_BE_NULL));
SetACookie(cookieService, "http://parser.test/", nullptr, " =eight", nullptr);
GetACookie(cookieService, "http://parser.test/", nullptr, cookie);
EXPECT_TRUE(CheckResult(cookie.get(), MUST_EQUAL, "eight"));
EXPECT_TRUE(CheckResult(cookie.get(), MUST_BE_NULL));
SetACookie(cookieService, "http://parser.test/", nullptr, "test=six",
nullptr);
GetACookie(cookieService, "http://parser.test/", nullptr, cookie);

View File

@ -1,19 +1,7 @@
[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,18 +1,4 @@
[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

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