Repository navigation
Description
Version
1.57.0 (and current main)
Steps to reproduce
Run the following self-contained test:
import { test, expect } from '@playwright/test';
test('send secure cookie over http for 127.0.0.1', async ({ request }) => {
// Add a secure cookie on 127.0.0.1
await request.addCookies([
{
name: 'auth_token',
value: 'secret123',
domain: '127.0.0.1',
path: '/',
secure: true,
}
]);
// Retrieve cookies for http://127.0.0.1
const cookies = await request.cookies(['http://127.0.0.1/']);
expect(cookies.map(c => c.name)).toEqual(['auth_token']);
});Or when an HTTP server running on http://127.0.0.1:<PORT> sends Set-Cookie: a=secret; Secure; Path=/:
On subsequent requests made to http://127.0.0.1:<PORT>/, the Cookie: a=secret header is omitted.
In contrast, replacing 127.0.0.1 with localhost preserves and sends the Secure cookie as expected.
Expected behavior
Under the W3C Secure Contexts specification (§3.1) and RFC 6761, IPv4 loopback (127.0.0.0/8, including 127.0.0.1) and IPv6 loopback (::1, [::1]) are defined as potentially trustworthy origins (secure contexts).
All major browsers (Chromium, WebKit/Safari, Firefox) treat http://127.0.0.1:<port> as a secure context and allow setting and sending Secure cookies over plain HTTP.
APIRequestContext and browserContext.cookies('http://127.0.0.1:<port>') should recognize loopback addresses as secure contexts and retain Secure cookies just like localhost.
Actual behavior
Secure cookies are filtered out and dropped on 127.0.0.1 and [::1]:
request.cookies(['http://127.0.0.1/'])returns[].APIRequestContextomits theCookieheader forSecurecookies on HTTP requests tohttp://127.0.0.1:<PORT>.browserContext.cookies('http://127.0.0.1:<PORT>')omitsSecurecookies.
Additional context
Root Cause:
In packages/playwright-core/src/server/network.ts:
export function isLocalHostname(hostname: string): boolean {
return hostname === 'localhost' || hostname.endsWith('.localhost');
}This helper only matches localhost and *.localhost. It does not match 127.0.0.1 (or 127.0.0.0/8) or ::1 / [::1].
As a result:
- In
packages/playwright-core/src/server/cookieStore.ts:33:if (this._raw.secure && (url.protocol !== 'https:' && !isLocalHostname(url.hostname))) return false;
- In
packages/playwright-core/src/server/network.ts:69:if (parsedURL.protocol !== 'https:' && !isLocalHostname(parsedURL.hostname) && c.secure) continue;
Many testing environments and CI setups explicitly configure http://127.0.0.1 instead of localhost to avoid dual-stack IPv4/IPv6 resolution delays or mismatches in Node.js, which currently leads to Secure cookies being silently dropped.
Environment
System:
OS: Windows 11 10.0.26200
CPU: (12) x64 12th Gen Intel(R) Core(TM) i5-1235U
Memory: 2.62 GB / 15.68 GB
Binaries:
Node: 22.14.0 - C:\Program Files\nodejs\node.EXE
npm: 10.9.2 - C:\Program Files\nodejs\npm.CMD
Activity
github-actions commentedon Oct 5, 2026
Hi, I'm the Playwright bot and I took a first look.
Reproduced on tip-of-tree (
1.64.0-next, shaa18dade). This is a live bug in Playwright's URL filtering: secure cookies are excluded for plain-HTTP IPv4 and IPv6 loopback URLs even though loopback is potentially trustworthy. It affectsAPIRequestContext.cookies(), outgoingAPIRequestContextcookie headers, andBrowserContext.cookies(); the result is the same across Chromium, Firefox, and WebKit.#43116 contains the matching fix. Applying its source diff to the tested sha makes the full 12-case matrix pass.
Condensed repro
What I ran
1.64.0-nextata18dade0076912787d4e848d08a3047dc4c8fc05127.0.0.1and[::1]APIRequestContext.cookies(), an actual outgoingAPIRequestContextrequest, andBrowserContext.cookies()3c26cbb); all 12 checks passTriaged on Linux by the Playwright bot - agent run