Bug 1629112 - Group console warnings about invalid sameSite cookie attributes, r=nchevobbe

Invalid sameSite cookie attributes generate console warning messages in the
wrong 'generic' category. In this patch, we put them under the 'sameSite'
category. We also rename the 'generic' category to 'oversize' because all the
remaining messages are about invalid cookie sizes.

Differential Revision: https://phabricator.services.mozilla.com/D70795
This commit is contained in:
Andrea Marchesini 2020-04-17 07:56:45 +00:00
Родитель 29b0030c60
Коммит 1611112ee4
2 изменённых файлов: 49 добавлений и 4 удалений

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

@ -104,3 +104,47 @@ add_task(async function testSameSiteCookieMessage() {
});
add_task(cleanUp);
add_task(async function testInvalidSameSiteMessage() {
await pushPref("network.cookie.sameSite.laxByDefault", true);
const groupLabel =
"Some cookies are misusing the “sameSite“ attribute, so it wont work as expected";
const message1 =
"Invalid “sameSite“ value for cookie “a”. The supported values are: “lax“, “strict“, “none“.";
const message2 =
"Cookie “a” has “sameSite” policy set to “lax” because it is missing a “sameSite” attribute, and “sameSite=lax” is the default value for this attribute.";
const { hud, tab, win } = await openNewWindowAndConsole(
"http://example.org/" + TEST_FILE
);
info("Test cookie messages");
SpecialPowers.spawn(tab.linkedBrowser, [], () => {
content.wrappedJSObject.createCookie("a=1; sameSite=batman");
});
const { node } = await waitForMessage(hud, groupLabel, ".warn");
is(
node.querySelector(".warning-group-badge").textContent,
"2",
"The badge has the expected text"
);
checkConsoleOutputForWarningGroup(hud, [`▶︎⚠ ${groupLabel} 2`]);
info("Open the group");
node.querySelector(".arrow").click();
await waitFor(() => findMessage(hud, "sameSite"));
checkConsoleOutputForWarningGroup(hud, [
`▼︎⚠ ${groupLabel} 2`,
`| ${message1}`,
`| ${message2}`,
]);
await win.close();
});
add_task(cleanUp);

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

@ -41,7 +41,8 @@ namespace net {
static StaticRefPtr<CookieService> gCookieService;
constexpr auto CONSOLE_SAMESITE_CATEGORY = NS_LITERAL_CSTRING("cookieSameSite");
constexpr auto CONSOLE_GENERIC_CATEGORY = NS_LITERAL_CSTRING("cookies");
constexpr auto CONSOLE_OVERSIZE_CATEGORY =
NS_LITERAL_CSTRING("cookiesOversize");
constexpr auto SAMESITE_MDN_URL = NS_LITERAL_STRING(
"https://developer.mozilla.org/docs/Web/HTTP/Headers/Set-Cookie/SameSite");
@ -877,7 +878,7 @@ bool CookieService::CanSetCookie(nsIURI* aHostURI,
params.AppendElement(size);
LogMessageToConsole(aChannel, aHostURI, nsIScriptError::warningFlag,
CONSOLE_GENERIC_CATEGORY,
CONSOLE_OVERSIZE_CATEGORY,
NS_LITERAL_CSTRING("CookieOversize"), params);
return newCookie;
}
@ -1282,7 +1283,7 @@ bool CookieService::ParseAttributes(nsIChannel* aChannel, nsIURI* aHostURI,
} else {
LogMessageToConsole(
aChannel, aHostURI, nsIScriptError::infoFlag,
CONSOLE_GENERIC_CATEGORY,
CONSOLE_SAMESITE_CATEGORY,
NS_LITERAL_CSTRING("CookieSameSiteValueInvalid"),
AutoTArray<nsString, 1>{NS_ConvertUTF8toUTF16(aCookieData.name())});
}
@ -1653,7 +1654,7 @@ bool CookieService::CheckPath(CookieStruct& aCookieData, nsIChannel* aChannel,
params.AppendElement(size);
LogMessageToConsole(aChannel, aHostURI, nsIScriptError::warningFlag,
CONSOLE_GENERIC_CATEGORY,
CONSOLE_OVERSIZE_CATEGORY,
NS_LITERAL_CSTRING("CookiePathOversize"), params);
return false;
}