Repository navigation
Description
Version
1.64.1
Steps to reproduce
- Create an empty folder containing the
repro.jsbelow and thispackage.json:{ "private": true, "dependencies": { "playwright": "1.64.1" } } npm installnode repro.js
The script starts a local site that logs every request it receives. It then runs npx playwright mcp --headless --isolated --caps=network --blocked-origins=<site origin> and sends three MCP calls:
browser_navigateto the blocked sitebrowser_routewith{ "pattern": "**", "headers": ["X-Test: 1"] }(nobody/status)browser_navigateto the blocked site again
repro.js
const { spawn } = require('child_process');
const http = require('http');
(async () => {
// Local site that logs every request it actually receives.
const site = http.createServer((req, res) => {
console.log(` [site] received ${req.url} (x-test: ${req.headers['x-test'] || 'none'})`);
res.setHeader('content-type', 'text/html');
res.end('<h1>reached</h1>');
});
await new Promise(r => site.listen(0, '127.0.0.1', r));
const origin = `http://127.0.0.1:${site.address().port}`;
const server = spawn('npx', ['playwright', 'mcp', '--headless', '--isolated', '--caps=network', `--blocked-origins=${origin}`],
{ stdio: ['pipe', 'pipe', 'inherit'] });
// Minimal MCP client over stdio.
let id = 0, buf = '';
const pending = new Map();
server.stdout.on('data', d => {
buf += d;
for (let i; (i = buf.indexOf('\n')) !== -1;) {
const line = buf.slice(0, i); buf = buf.slice(i + 1);
const msg = line.trim() && JSON.parse(line);
if (msg && pending.has(msg.id)) { pending.get(msg.id)(msg); pending.delete(msg.id); }
}
});
const rpc = (method, params) => new Promise(resolve => {
pending.set(++id, resolve);
server.stdin.write(JSON.stringify({ jsonrpc: '2.0', id, method, params }) + '\n');
});
const call = async (name, args) => (await rpc('tools/call', { name, arguments: args })).result.content.map(c => c.text).join('\n');
const outcome = text => text.match(/net::ERR_\w+/)?.[0] || 'loaded ' + text.match(/Page URL: (.*)/)?.[1];
await rpc('initialize', { protocolVersion: '2025-06-18', capabilities: {}, clientInfo: { name: 'repro', version: '1' } });
server.stdin.write(JSON.stringify({ jsonrpc: '2.0', method: 'notifications/initialized' }) + '\n');
console.log(`blocked origin: ${origin}`);
console.log('1. browser_navigate ->', outcome(await call('browser_navigate', { url: `${origin}/before` })));
console.log('2. browser_route (headers) ->', (await call('browser_route', { pattern: '**', headers: ['X-Test: 1'] })).match(/Route added.*/)[0]);
console.log('3. browser_navigate ->', outcome(await call('browser_navigate', { url: `${origin}/after` })));
server.kill();
site.close();
})();Expected behavior
Step 3 is still blocked (net::ERR_BLOCKED_BY_CLIENT), the same as step 1. Adding a header-only route should not change which origins the browser may request.
Actual behavior
Step 3 loads the blocked origin, and the site receives the request with the added header:
blocked origin: http://127.0.0.1:49726
1. browser_navigate -> net::ERR_BLOCKED_BY_CLIENT
2. browser_route (headers) -> Route added for pattern: **
[site] received /after (x-test: 1)
3. browser_navigate -> loaded http://127.0.0.1:49726/after
--allowed-origins is bypassed the same way: with --allowed-origins=https://example.com instead, the output is identical.
Additional context
The origin filters are installed as context routes when the context is set up (context.ts#L432-L442). browser_route handlers are registered later (context.ts#L477), so they run first. The header-only branch then sends the request straight to the network (route.ts#L80):
await route.continue({ headers });Using route.fallback({ headers }) there would keep the header change and still let the origin-filter routes run. In a plain Playwright check with an abort route registered first and a header route registered second, continue() loads the page and fallback() keeps it blocked.
I understand the flags are documented as not a security boundary. This report is only about them silently stopping working once a header-only route exists.
Environment
System:
OS: macOS 27.0.1
CPU: (10) arm64 Apple M4
Memory: 450.25 MB / 16.00 GB
Binaries:
Node: 22.23.1 - ~/.volta/tools/image/node/22.23.1/bin/node
npm: 11.12.1 - ~/.volta/tools/image/npm/11.12.1/bin/npm
pnpm: 11.14.0 - ~/.volta/bin/pnpm
IDEs:
VSCode: 1.142.0 - /usr/local/bin/code
Languages:
Bash: 3.2.57 - /bin/bash
npmPackages:
playwright: ^1.64.1 => 1.64.1
Activity
dhruv-techdev commentedon Oct 24, 2026
I'd like to work on this. I have a fix ready on my fork: a one-line change in
packages/playwright-core/src/tools/backend/route.ts(route.continue({ headers })→route.fallback({ headers })) plus a regression test intests/mcp/request-blocking.spec.ts.Branch: https://github.com/dhruv-techdev/playwright/tree/fix-mcp-route-blocked-origins
Happy to open a PR if this approach looks right.
sunny-kavixo commentedon Oct 24, 2026
Hi Dhruv P. (@dhruv-techdev),
Thanks for the detailed reproduction and proposed fix.
I noticed you've already prepared a fix on your fork, so I don't want to duplicate your work.
I'd be happy to independently review and validate the proposed
route.continue()→route.fallback()change, particularly whether origin restrictions remain effective while custom headers are preserved.I can also help check regression coverage for both
--blocked-originsand--allowed-origins, including potential interactions with existing route handlers.If you're planning to open a PR, I'd be glad to review the changes and share any additional findings.
Thanks!
Putluru Sandeep (Putluru Sandeep (@sunny-kavixo))
github-actions commentedon Oct 25, 2026
Hi, I'm the Playwright bot and I reproduced this on Linux.
Reproduced on
1.65.0-next(91a765d1681cb3eeb0d0fb89fefec3cf0d21bd9b) in Chromium, Firefox, and WebKit. Header-only routes callcontinue(), which skips the earlier origin-filter routes. Usingfallback({ headers })preserves the header changes and both origin restrictions. A verified fix proposal is ready.Verification
Extended the existing
browser_route modifies request headerstest. It permits the HTTP test-server origin, permits but explicitly blocks the HTTPS test-server origin, and leaves the alternate HTTP hostname unlisted. After adding a**header-only route, the permitted request must retain its custom header, and navigation to both other origins must fail with the browser's blocked-request error. Fixture HTTPS certificate errors are ignored to isolate origin filtering.Before the fix, both restricted origins loaded in all three browsers. After the fix, the regression and neighbouring route tests passed:
All 99 selected tests passed.
npm run buildandnpm run flintalso passed. These runs were headless on Linux; the reported macOS environment and published1.64.1were not tested.Draft fix: #43637
Triaged on Linux by the Playwright bot - agent run
chore: mark v0.1.23 (#494)