Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions packages/playwright-core/src/tools/utils/mcp/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import crypto from 'crypto';
import debug from 'debug';
import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
import { isUnderTest } from '@utils/debug';
import { urlHostFromAddress } from '@utils/httpServer';
import { createHttpServer, startHttpServer } from '@utils/network';
import { ManualPromise } from '@isomorphic/manualPromise';
Expand Down Expand Up @@ -82,14 +83,7 @@ async function installHttpTransport(httpServer: http.Server, serverBackendFactor
}

const url = new URL(`http://localhost${req.url}`);
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();
}
if (url.pathname === '/killkillkill' && isUnderTest()) {
res.statusCode = 200;
res.end('Killing process');
// Simulate Ctrl+C in a way that works on Windows too.
Expand Down
2 changes: 1 addition & 1 deletion tests/mcp/http.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ test('http transport browser sigint', async ({ serverEndpoint, server }) => {
arguments: { url: server.HELLO_WORLD },
});

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

await expect.poll(() => formatLog(stderr())).toEqual({
'create browser (isolated)': 1,
Expand Down
Loading