fix(web)!: scope headers and basicAuth to the app's origin
web({ basicAuth }) answered a 401 from any origin, and web({ headers }) went to every host on the app's site: another port on the same host, sibling subdomains, every host under a shared domain such as vercel.app. A third-party origin the app embeds could collect a preview password or a x-vercel-protection-bypass token. Fixes ENG-846.
What changed
- Both now go to the app's origin only: the scheme, host, and port of
app.url. - One new option,
credentialOrigins, lists extra origins for both. Each entry must be an exacthttp:/https:origin, elseINVALID_CONFIGat config load. That includes a*in the host and port0, which would match nothing. basicAuthbecomes Playwright's per-originhttpCredentialsarray, one entry per allowed origin (packages/web/src/protected-app.ts).- WebKit is the exception. It never matches a scoped credential to an origin on a default port (443/80) or with an IPv6 host. When an allowed origin is one of those, WebKit gets one unscoped credential, as on main, and the docs say so.
- The engine only knew the app's site, so the runner now passes
EngineAppInfo.origintoprepareandinit(packages/e2e/src/config/app.ts). It carries the run's real port whenapp.urluses port0, and is left out until that port is assigned (e2e doctor). @e2e-dev/webraises itse2epeer floor to>=0.23.1. On an older runner,initfails withINVALID_CONFIGinstead of sending credentials nowhere. If #1590 releases 0.23.1 first, the floor moves to 0.23.2 when I rebase.browser.route'sroute.continue()androute.fetch()add the configured headers under the same origin rule.- Breaking for
@e2e-dev/web(minor,**Breaking:**). The changeset carries the migration note.
engine: web({
headers: { 'x-vercel-protection-bypass': process.env.VERCEL_BYPASS! },
basicAuth: { username: 'preview', password: secrets.get('previewPassword') },
credentialOrigins: ['https://api.example.com'],
}),
Not changed: a header Playwright injects into a request stays on that request's redirects, to any origin. Playwright reapplies a routed request's headers to every redirect hop without routing the hop (crNetworkManager, _alreadyContinuedParams). This was already true on main. The docs now say so, and a test pins it. Closing it means fetching outside the browser with route.fetch({ maxRedirects: 0 }), which costs the HTTP cache and streaming, so it's out of scope here.
Verified
Ran it locally: yes
- I built the CLI and ran a scratch project against a gate server. The app runs on one port and the same gate listens on a second port of the same host. Each page reports the header it received and whether basic auth passed.
| Case | main | this branch | branch, other port in credentialOrigins |
|---|---|---|---|
| App origin: header / basic auth | on / Protected | on / Protected | on / Protected |
| Other port: header | on (the bug) | none | on |
| Other port: basic auth | Protected (the bug) | Unauthorized | Protected |
- The CLI refuses
credentialOrigins: ['https://*.vercel.app']and['http://127.0.0.1:0']at load withINVALID_CONFIG, naming the entry. - WebKit on macOS with Playwright 1.64.1, headless, against a basic-auth server. Chromium answers in every case.
| WebKit | scoped credential | unscoped (this branch's fallback) |
|---|---|---|
| port 80 | Unauthorized | Protected |
| a free port | Protected | - |
[::1] | Unauthorized | Protected |
- New integration tests cover the bug cases.
protected-app.test.tssends a request to another port on the same host and to a third-party site, for bothheadersandbasicAuth, with and without the extra origin, plus redirects in both directions.routes.test.tscoverscontinue({ url })androute.fetch()to another port on the same host and to a listed one. Both new route tests fail against main's engine source. - Earlier, the same tests ran headed on macOS (Chromium). Headed Chromium fails a navigation to an unanswered
401withERR_INVALID_AUTH_CREDENTIALSrather than rendering the page. Main does the same for any unanswered401, but now more origins go unanswered. pnpm checkandpnpm testpass.
Opus 5.5 in Claude Code (T3 Code). Reviewed by Fable 5.1.