fix(fetch): cookie with domain=localhost (#18998)
Fixes https://github.com/microsoft/playwright/issues/18362
This commit is contained in:
parent
f97dcd4c79
commit
d3f41eaa47
|
|
@ -207,7 +207,7 @@ export abstract class APIRequestContext extends SdkObject {
|
||||||
if (!cookie.domain)
|
if (!cookie.domain)
|
||||||
cookie.domain = url.hostname;
|
cookie.domain = url.hostname;
|
||||||
else
|
else
|
||||||
assert(cookie.domain.startsWith('.'));
|
assert(cookie.domain.startsWith('.') || !cookie.domain.includes('.'));
|
||||||
if (!domainMatches(url.hostname, cookie.domain!))
|
if (!domainMatches(url.hostname, cookie.domain!))
|
||||||
continue;
|
continue;
|
||||||
// https://datatracker.ietf.org/doc/html/rfc6265#section-5.2.4
|
// https://datatracker.ietf.org/doc/html/rfc6265#section-5.2.4
|
||||||
|
|
@ -587,7 +587,7 @@ function parseCookie(header: string): channels.NetworkCookie | null {
|
||||||
break;
|
break;
|
||||||
case 'domain':
|
case 'domain':
|
||||||
cookie.domain = value.toLocaleLowerCase() || '';
|
cookie.domain = value.toLocaleLowerCase() || '';
|
||||||
if (cookie.domain && !cookie.domain.startsWith('.'))
|
if (cookie.domain && !cookie.domain.startsWith('.') && cookie.domain.includes('.'))
|
||||||
cookie.domain = '.' + cookie.domain;
|
cookie.domain = '.' + cookie.domain;
|
||||||
break;
|
break;
|
||||||
case 'path':
|
case 'path':
|
||||||
|
|
|
||||||
|
|
@ -1072,6 +1072,19 @@ it('should support SameSite cookie attribute over https', async ({ contextFactor
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should set domain=localhost cookie', async ({ context, server, browserName, isWindows }) => {
|
||||||
|
server.setRoute('/empty.html', (req, res) => {
|
||||||
|
res.setHeader('Set-Cookie', `name=val; Domain=localhost; Path=/;`);
|
||||||
|
res.end();
|
||||||
|
});
|
||||||
|
await context.request.get(server.EMPTY_PAGE);
|
||||||
|
const [cookie] = await context.cookies();
|
||||||
|
expect(cookie).toBeTruthy();
|
||||||
|
expect(cookie.name).toBe('name');
|
||||||
|
expect(cookie.value).toBe('val');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should support set-cookie with SameSite and without Secure attribute over HTTP', async ({ page, server, browserName, isWindows }) => {
|
it('should support set-cookie with SameSite and without Secure attribute over HTTP', async ({ page, server, browserName, isWindows }) => {
|
||||||
for (const value of ['None', 'Lax', 'Strict']) {
|
for (const value of ['None', 'Lax', 'Strict']) {
|
||||||
await it.step(`SameSite=${value}`, async () => {
|
await it.step(`SameSite=${value}`, async () => {
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,26 @@ it('should use proxy', async ({ contextFactory, server, proxyServer }) => {
|
||||||
await context.close();
|
await context.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('should set cookie for top-level domain', async ({ contextFactory, server, proxyServer, browserName, isLinux }) => {
|
||||||
|
it.fixme(browserName === 'webkit' && isLinux);
|
||||||
|
proxyServer.forwardTo(server.PORT);
|
||||||
|
const context = await contextFactory({
|
||||||
|
proxy: { server: `localhost:${proxyServer.PORT}` }
|
||||||
|
});
|
||||||
|
server.setRoute('/empty.html', (req, res) => {
|
||||||
|
res.setHeader('Set-Cookie', `name=val; Domain=codes; Path=/;`);
|
||||||
|
res.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
await context.request.get('http://codes/empty.html');
|
||||||
|
const [cookie] = await context.cookies();
|
||||||
|
expect(cookie).toBeTruthy();
|
||||||
|
expect(cookie.name).toBe('name');
|
||||||
|
expect(cookie.value).toBe('val');
|
||||||
|
await context.close();
|
||||||
|
});
|
||||||
|
|
||||||
it.describe('should proxy local network requests', () => {
|
it.describe('should proxy local network requests', () => {
|
||||||
for (const additionalBypass of [false, true]) {
|
for (const additionalBypass of [false, true]) {
|
||||||
it.describe(additionalBypass ? 'with other bypasses' : 'by default', () => {
|
it.describe(additionalBypass ? 'with other bypasses' : 'by default', () => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue