Skip to content

Commit 91f2cef

Browse files
Skn0ttCopilot
andauthored
fix(mcp): only enable /killkillkill under test (#42133)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: bcb5b8bb-90b5-4bc9-baae-64ab11a9c665
1 parent 3afd6ce commit 91f2cef

2 files changed

Lines changed: 3 additions & 9 deletions

File tree

packages/playwright-core/src/tools/utils/mcp/http.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import crypto from 'crypto';
2222
import debug from 'debug';
2323
import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
2424
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
25+
import { isUnderTest } from '@utils/debug';
2526
import { urlHostFromAddress } from '@utils/httpServer';
2627
import { createHttpServer, startHttpServer } from '@utils/network';
2728
import { ManualPromise } from '@isomorphic/manualPromise';
@@ -82,14 +83,7 @@ async function installHttpTransport(httpServer: http.Server, serverBackendFactor
8283
}
8384

8485
const url = new URL(`http://localhost${req.url}`);
85-
if (url.pathname === '/killkillkill') {
86-
// Require POST plus a custom header to prevent cross-origin CSRF
87-
// (a browser-coerced <img> GET or simple <form> POST can't add custom headers,
88-
// and any cross-origin request with custom headers is blocked by CORS preflight).
89-
if (req.method !== 'POST' || req.headers['x-pw-mcp-kill'] !== '1') {
90-
res.statusCode = 405;
91-
return res.end();
92-
}
86+
if (url.pathname === '/killkillkill' && isUnderTest()) {
9387
res.statusCode = 200;
9488
res.end('Killing process');
9589
// Simulate Ctrl+C in a way that works on Windows too.

tests/mcp/http.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ test('http transport browser sigint', async ({ serverEndpoint, server }) => {
152152
arguments: { url: server.HELLO_WORLD },
153153
});
154154

155-
await fetch(new URL('/killkillkill', url).href, { method: 'POST', headers: { 'x-pw-mcp-kill': '1' } }).catch(() => {});
155+
await fetch(new URL('/killkillkill', url).href).catch(() => {});
156156

157157
await expect.poll(() => formatLog(stderr())).toEqual({
158158
'create browser (isolated)': 1,

0 commit comments

Comments
 (0)