Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(mcp): require POST + custom header on /killkillkill (#40551)

Pavel Feldman4a80eed39607
diff --git a/packages/playwright-core/src/tools/utils/mcp/http.ts b/packages/playwright-core/src/tools/utils/mcp/http.ts
index 4d621ae6e4..c630b8693d 100644
--- a/packages/playwright-core/src/tools/utils/mcp/http.ts
+++ b/packages/playwright-core/src/tools/utils/mcp/http.ts
@@ -80,7 +80,14 @@ async function installHttpTransport(httpServer: http.Server, serverBackendFactor
}
const url = new URL(`http://localhost${req.url}`);
- if (url.pathname === '/killkillkill' && req.method === 'GET') {
+ if (url.pathname === '/killkillkill') {
+ // Require POST plus a custom header to prevent cross-origin CSRF
+ // (a browser-coerced <img> GET or simple <form> POST can't add custom headers,
+ // and any cross-origin request with custom headers is blocked by CORS preflight).
+ if (req.method !== 'POST' || req.headers['x-pw-mcp-kill'] !== '1') {
+ res.statusCode = 405;
+ return res.end();
+ }
res.statusCode = 200;
res.end('Killing process');
// Simulate Ctrl+C in a way that works on Windows too.
diff --git a/tests/mcp/http.spec.ts b/tests/mcp/http.spec.ts
index 4be3613008..6ea03c9e84 100644
--- a/tests/mcp/http.spec.ts
+++ b/tests/mcp/http.spec.ts
@@ -150,7 +150,7 @@ test('http transport browser sigint', async ({ serverEndpoint, server }) => {
arguments: { url: server.HELLO_WORLD },
});
- await fetch(new URL('/killkillkill', url).href).catch(() => {});
+ await fetch(new URL('/killkillkill', url).href, { method: 'POST', headers: { 'x-pw-mcp-kill': '1' } }).catch(() => {});
await expect.poll(() => formatLog(stderr())).toEqual({
'create browser (isolated)': 1,