Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return non-secure cookies with HTTPS URLs #5507

Merged
merged 3 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/server/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function filterCookies(cookies: types.NetworkCookie[], urls: string[]): t
continue;
if (!parsedURL.pathname.startsWith(c.path))
continue;
if ((parsedURL.protocol === 'https:') !== c.secure)
if ((parsedURL.protocol !== 'https:') && c.secure)
aslushnikov marked this conversation as resolved.
Show resolved Hide resolved
continue;
return true;
}
Expand Down
57 changes: 49 additions & 8 deletions test/browsercontext-cookies.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,9 @@ it('should get multiple cookies', async ({context, page, server}) => {
document.cookie = 'password=1234';
return document.cookie.split('; ').sort().join('; ');
});
const cookies = await context.cookies();
cookies.sort((a, b) => a.name.localeCompare(b.name));
const cookies = new Set(await context.cookies());
expect(documentCookie).toBe('password=1234; username=John Doe');
expect(cookies).toEqual([
expect(cookies).toEqual(new Set([
{
name: 'password',
value: '1234',
Expand All @@ -130,7 +129,7 @@ it('should get multiple cookies', async ({context, page, server}) => {
secure: false,
sameSite: 'None',
},
]);
]));
});

it('should get cookies from multiple urls', async ({context}) => {
Expand All @@ -147,9 +146,8 @@ it('should get cookies from multiple urls', async ({context}) => {
name: 'birdo',
value: 'tweets',
}]);
const cookies = await context.cookies(['https://foo.com', 'https://baz.com']);
cookies.sort((a, b) => a.name.localeCompare(b.name));
expect(cookies).toEqual([{
const cookies = new Set(await context.cookies(['https://foo.com', 'https://baz.com']));
expect(cookies).toEqual(new Set([{
name: 'birdo',
value: 'tweets',
domain: 'baz.com',
Expand All @@ -167,7 +165,7 @@ it('should get cookies from multiple urls', async ({context}) => {
httpOnly: false,
secure: true,
sameSite: 'None',
}]);
}]));
});

it('should work with subdomain cookie', async ({context, page, server}) => {
Expand Down Expand Up @@ -210,3 +208,46 @@ it('should not return cookies with empty value', async ({context, page, server})
expect(cookies.length).toBe(0);
});

it('should return secure cookies based on HTTP(S) protocol', async ({context}) => {
await context.addCookies([{
url: 'https://foo.com',
name: 'doggo',
value: 'woofs',
secure: true
}, {
url: 'http://foo.com',
name: 'catto',
value: 'purrs',
secure: false
}]);
const cookies = new Set(await context.cookies('https://foo.com'));
expect(cookies).toEqual(new Set([{
name: 'catto',
value: 'purrs',
domain: 'foo.com',
path: '/',
expires: -1,
httpOnly: false,
secure: false,
sameSite: 'None',
}, {
name: 'doggo',
value: 'woofs',
domain: 'foo.com',
path: '/',
expires: -1,
httpOnly: false,
secure: true,
sameSite: 'None',
}]));
expect(await context.cookies('http://foo.com/')).toEqual([{
name: 'catto',
value: 'purrs',
domain: 'foo.com',
path: '/',
expires: -1,
httpOnly: false,
secure: false,
sameSite: 'None',
}]);
});