mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(fetch): send secure cookies for http://localhost requests (#12450)
This commit is contained in:
parent
4b19d59ec5
commit
2d7ec26dc2
@ -28,7 +28,7 @@ class Cookie {
|
|||||||
|
|
||||||
// https://datatracker.ietf.org/doc/html/rfc6265#section-5.4
|
// https://datatracker.ietf.org/doc/html/rfc6265#section-5.4
|
||||||
matches(url: URL): boolean {
|
matches(url: URL): boolean {
|
||||||
if (this._raw.secure && url.protocol !== 'https:')
|
if (this._raw.secure && (url.protocol !== 'https:' && url.hostname !== 'localhost'))
|
||||||
return false;
|
return false;
|
||||||
if (!domainMatches(url.hostname, this._raw.domain))
|
if (!domainMatches(url.hostname, this._raw.domain))
|
||||||
return false;
|
return false;
|
||||||
|
@ -36,7 +36,7 @@ export function filterCookies(cookies: types.NetworkCookie[], urls: string[]): t
|
|||||||
continue;
|
continue;
|
||||||
if (!parsedURL.pathname.startsWith(c.path))
|
if (!parsedURL.pathname.startsWith(c.path))
|
||||||
continue;
|
continue;
|
||||||
if (parsedURL.protocol !== 'https:' && c.secure)
|
if (parsedURL.protocol !== 'https:' && parsedURL.hostname !== 'localhost' && c.secure)
|
||||||
continue;
|
continue;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -900,6 +900,19 @@ it('context request should export same storage state as context', async ({ conte
|
|||||||
expect(pageState).toEqual(contextState);
|
expect(pageState).toEqual(contextState);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should send secure cookie over http for localhost', async ({ page, server }) => {
|
||||||
|
server.setRoute('/setcookie.html', (req, res) => {
|
||||||
|
res.setHeader('Set-Cookie', ['a=v; secure']);
|
||||||
|
res.end();
|
||||||
|
});
|
||||||
|
await page.request.get(`${server.PREFIX}/setcookie.html`);
|
||||||
|
const [serverRequest] = await Promise.all([
|
||||||
|
server.waitForRequest('/empty.html'),
|
||||||
|
page.request.get(server.EMPTY_PAGE)
|
||||||
|
]);
|
||||||
|
expect(serverRequest.headers.cookie).toBe('a=v');
|
||||||
|
});
|
||||||
|
|
||||||
it('should accept bool and numeric params', async ({ page, server }) => {
|
it('should accept bool and numeric params', async ({ page, server }) => {
|
||||||
let request;
|
let request;
|
||||||
const url = new URL(server.EMPTY_PAGE);
|
const url = new URL(server.EMPTY_PAGE);
|
||||||
|
@ -138,6 +138,19 @@ it('should send secure cookie over https', async ({ request, server, httpsServer
|
|||||||
expect(serverRequest.headers.cookie).toBe('a=v; b=v');
|
expect(serverRequest.headers.cookie).toBe('a=v; b=v');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should send secure cookie over http for localhost', async ({ request, server }) => {
|
||||||
|
server.setRoute('/setcookie.html', (req, res) => {
|
||||||
|
res.setHeader('Set-Cookie', ['a=v; secure', 'b=v']);
|
||||||
|
res.end();
|
||||||
|
});
|
||||||
|
await request.get(`${server.PREFIX}/setcookie.html`);
|
||||||
|
const [serverRequest] = await Promise.all([
|
||||||
|
server.waitForRequest('/empty.html'),
|
||||||
|
request.get(server.EMPTY_PAGE)
|
||||||
|
]);
|
||||||
|
expect(serverRequest.headers.cookie).toBe('a=v; b=v');
|
||||||
|
});
|
||||||
|
|
||||||
it('should send not expired cookies', async ({ request, server }) => {
|
it('should send not expired cookies', async ({ request, server }) => {
|
||||||
server.setRoute('/setcookie.html', (req, res) => {
|
server.setRoute('/setcookie.html', (req, res) => {
|
||||||
const tomorrow = new Date();
|
const tomorrow = new Date();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user