mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 17:50:38 +00:00
* 🐛 Check Host and Origin headers in the MCP server The MCP endpoint, the REPL server and the plugin WebSocket accepted requests with any Host and Origin header, so a web page open in the user's browser could drive a local MCP server: connect as the plugin and call its tools. RequestGuard checks both headers against an allowlist and rejects other requests with HTTP 403, or WebSocket close code 1008. The list comes from PENPOT_MCP_ALLOWED_HOSTS, where "*" turns the check off. When it is unset, local mode allows only loopback names and remote mode allows any host, since remote mode relies on user tokens and has no file access. AI-assisted-by: claude-opus-5-5 * 🐛 Keep the Host and Origin check on in single-user remote mode The default allowlist followed remote mode, so a single-user server with PENPOT_MCP_REMOTE_MODE=true accepted any Host and Origin. It requires no user token either, so a web page could still drive it and run code in the user's Penpot session. The default now follows multi-user mode: single-user servers allow only loopback names, and multi-user servers, which rely on user tokens, allow any host. Startup warns when the check is off in single-user mode. PENPOT_MCP_ALLOWED_HOSTS entries with a scheme, port or path never matched, so every request failed with 403. The server now refuses to start and names the bad entry. AI-assisted-by: claude-opus-5-5
20 lines
747 B
TypeScript
20 lines
747 B
TypeScript
/**
|
|
* WebSocket close code the MCP server uses for policy violations.
|
|
*
|
|
* The server rejects a second plugin connection for the same user token,
|
|
* connections missing a token in multi-user mode, and connections whose `Host`
|
|
* or `Origin` is not allowed, with this code.
|
|
*/
|
|
export const WS_CLOSE_POLICY_VIOLATION = 1008;
|
|
|
|
/**
|
|
* Returns whether a WebSocket close should trigger an automatic reconnect.
|
|
*
|
|
* Policy violations are terminal: the server refuses the connection again
|
|
* immediately, so retrying only repeats the rejection. Other closes (for
|
|
* example a dropped or restarted server) are retried with backoff.
|
|
*/
|
|
export function shouldReconnectAfterClose(code: number): boolean {
|
|
return code !== WS_CLOSE_POLICY_VIOLATION;
|
|
}
|