Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix: do not return cookies with empty values (#5147)

Pavel Feldman87a3ccc49e72
diff --git a/src/server/network.ts b/src/server/network.ts
index d1ea76c40c..e44443d8f2 100644
--- a/src/server/network.ts
+++ b/src/server/network.ts
@@ -23,6 +23,9 @@ export function filterCookies(cookies: types.NetworkCookie[], urls: string[]): t
const parsedURLs = urls.map(s => new URL(s));
// Chromiums's cookies are missing sameSite when it is 'None'
return cookies.filter(c => {
+ // Firefox and WebKit can return cookies with empty values.
+ if (!c.value)
+ return false;
if (!parsedURLs.length)
return true;
for (const parsedURL of parsedURLs) {
diff --git a/test/browsercontext-cookies.spec.ts b/test/browsercontext-cookies.spec.ts
index 3b9d7dac70..ef46b36235 100644
--- a/test/browsercontext-cookies.spec.ts
+++ b/test/browsercontext-cookies.spec.ts
@@ -199,3 +199,14 @@ it('should work with subdomain cookie', async ({context, page, server}) => {
sameSite: 'None',
}]);
});
+
+it('should not return cookies with empty value', async ({context, page, server}) => {
+ server.setRoute('/empty.html', (req, res) => {
+ res.setHeader('Set-Cookie', 'name=;Path=/');
+ res.end();
+ });
+ await page.goto(server.EMPTY_PAGE);
+ const cookies = await context.cookies();
+ expect(cookies.length).toBe(0);
+});
+