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)
|
||||
cookie.domain = url.hostname;
|
||||
else
|
||||
assert(cookie.domain.startsWith('.'));
|
||||
assert(cookie.domain.startsWith('.') || !cookie.domain.includes('.'));
|
||||
if (!domainMatches(url.hostname, cookie.domain!))
|
||||
continue;
|
||||
// https://datatracker.ietf.org/doc/html/rfc6265#section-5.2.4
|
||||
|
|
@ -587,7 +587,7 @@ function parseCookie(header: string): channels.NetworkCookie | null {
|
|||
break;
|
||||
case 'domain':
|
||||
cookie.domain = value.toLocaleLowerCase() || '';
|
||||
if (cookie.domain && !cookie.domain.startsWith('.'))
|
||||
if (cookie.domain && !cookie.domain.startsWith('.') && cookie.domain.includes('.'))
|
||||
cookie.domain = '.' + cookie.domain;
|
||||
break;
|
||||
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 }) => {
|
||||
for (const value of ['None', 'Lax', 'Strict']) {
|
||||
await it.step(`SameSite=${value}`, async () => {
|
||||
|
|
|
|||
|
|
@ -91,6 +91,26 @@ it('should use proxy', async ({ contextFactory, server, proxyServer }) => {
|
|||
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', () => {
|
||||
for (const additionalBypass of [false, true]) {
|
||||
it.describe(additionalBypass ? 'with other bypasses' : 'by default', () => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue