Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: tighter Figma key and address checks

ogsamratd70938c006c9
diff --git a/apps/app/src/react-app/domains/settings/pages/mcp-view.tsx b/apps/app/src/react-app/domains/settings/pages/mcp-view.tsx
index db5fee50..2a0531fe 100644
--- a/apps/app/src/react-app/domains/settings/pages/mcp-view.tsx
+++ b/apps/app/src/react-app/domains/settings/pages/mcp-view.tsx
@@ -567,9 +567,12 @@ export function McpView(props: McpViewProps) {
});
return result.ok ? { ok: true } : { ok: false, error: result.error };
};
+ // The engine knows the server by the list's id (its plugin renames the entry), whatever the config calls it.
const signInSupportedMcp = (name: string) => {
const server = props.mcpServers.find((entry) => entry.name === name);
- if (server) props.authorizeMcp(server);
+ const decision = mcpPolicy?.decisions.find((entry) => entry.name === name);
+ const engineName = decision?.renamed_to ?? decision?.id ?? name;
+ if (server) props.authorizeMcp({ ...server, name: engineName });
};
const libraryDetailLists = {
quickConnect: quickConnectList,
diff --git a/apps/server/src/mcp-allow/PARITY.sha256 b/apps/server/src/mcp-allow/PARITY.sha256
index b410a9cc..aeab23b3 100644
--- a/apps/server/src/mcp-allow/PARITY.sha256
+++ b/apps/server/src/mcp-allow/PARITY.sha256
@@ -1,4 +1,4 @@
# The MCP allowlist module: the same files in omnirush-cli (src/mcp/) and omnirush-gui (apps/server/src/mcp-allow/).
# A change to one must be ported to the other and this list updated in both.
-80be9bea990f9de88899e4785828f6352b7f36c8a249bcac30882fabbfb0c97a mcp-allow.mjs
+42879c5c348f59c70af4f85aeba02526557ad6a66290196c0175a646908aea8a mcp-allow.mjs
482fb25ea7dba6dc91aeeb24891e0b2e94d4abe8ff585b0068eb2a7575e75491 mcp-allow.d.mts
diff --git a/apps/server/src/mcp-allow/mcp-allow.mjs b/apps/server/src/mcp-allow/mcp-allow.mjs
index 88e81c1d..ab49ada0 100644
--- a/apps/server/src/mcp-allow/mcp-allow.mjs
+++ b/apps/server/src/mcp-allow/mcp-allow.mjs
@@ -166,16 +166,27 @@ function normalizeRules(value) {
}
/** A remote server's address as compared: scheme, host and path, lower-case host, no trailing slash. */
+// The same check as the backend's mcp_policy.remote_url (test/fixtures/mcp-remote-urls.json, both sides): plain
+// host names only (no escapes, IP shortcuts or trailing dot), a port without leading zeros, a path without
+// escapes or dot segments, no user, query or fragment.
+const REMOTE_URL = /^(https?):\/\/((?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)*|\[::1\])(?::([1-9][0-9]{0,4}))?(\/[A-Za-z0-9._~/-]*)?$/i;
+
export function normalizeRemoteUrl(value) {
- let u;
- try { u = new URL(String(value ?? "")); } catch { return null; }
- if (u.protocol !== "https:" && u.protocol !== "http:") return null;
- if (u.username || u.password || u.search || u.hash) return null;
+ if (typeof value !== "string" || value.length > 300) return null;
+ const m = REMOTE_URL.exec(value);
+ if (!m) return null;
+ const scheme = m[1].toLowerCase();
+ let host = m[2].toLowerCase();
+ let port = m[3] ?? null;
+ const path = m[4] ?? "";
+ if (port !== null && Number(port) > 65535) return null;
+ if (path.split("/").some((part) => part === "." || part === "..")) return null;
// Plain http only to this computer (the Figma desktop app's server); anything else must be https.
- if (u.protocol === "http:" && !["127.0.0.1", "localhost", "[::1]"].includes(u.hostname)) return null;
+ if (scheme === "http" && !["127.0.0.1", "localhost", "[::1]"].includes(host)) return null;
// localhost and 127.0.0.1 name the same server here.
- const host = u.hostname.toLowerCase() === "localhost" ? `127.0.0.1${u.port ? `:${u.port}` : ""}` : u.host.toLowerCase();
- return `${u.protocol}//${host}${u.pathname.replace(/\/+$/, "") || "/"}`;
+ if (host === "localhost") host = "127.0.0.1";
+ if ((scheme === "https" && port === "443") || (scheme === "http" && port === "80")) port = null;
+ return `${scheme}://${host}${port ? `:${port}` : ""}${path.replace(/\/+$/, "") || "/"}`;
}
function normalizeRemoteEntry(value, id) {
@@ -570,8 +581,18 @@ export function evaluateMcp(mcpMap, policy, ctx = {}) {
if (ignored.length) notes.push(`ignores ${ignored.slice(0, 4).join(", ")}${ignored.length > 4 ? " ..." : ""}`);
let refusal = null;
const userEnv = ctx.env ?? process.env;
+ if (!refusal && rules.secret_env) {
+ // A key server takes its flags only: a bare argument could be the key itself (in the config, and in
+ // the process list). A path flag's value is the one argument allowed.
+ for (let i = 0; i < rest.length; i += 1) {
+ const arg = String(rest[i]);
+ if (arg.startsWith("-")) { if (!arg.includes("=") && (rules.path_flags ?? []).includes(arg)) i += 1; continue; }
+ refusal = blocked(name, "flag", { ...base, version, reason: MCP_REASONS.secret_flag });
+ break;
+ }
+ }
const secretNames = (rules.secret_env ?? []).filter((k) => typeof userEnv[k] === "string" && userEnv[k] !== "");
- if (rules.secret_env && !secretNames.length) {
+ if (!refusal && rules.secret_env && !secretNames.length) {
refusal = blocked(name, "secret_missing", { ...base, version, reason: `${MCP_REASONS.secret_missing} Set ${rules.secret_env.join(" or ")} before starting the app.` });
}
// A server that needs the person's key runs on this computer, where the engine's own environment holds it
@@ -655,7 +676,9 @@ export function evaluateMcp(mcpMap, policy, ctx = {}) {
}
argv.splice(0, 1, ...program);
}
- const next = { ...raw, type: "local" };
+ // Only the keys the engine uses for a local server: anything else in the entry (headers, a token under
+ // another name) never reaches the engine's config.
+ const next = { type: "local", ...Object.fromEntries(["command", "environment", "enabled", "timeout", "cwd"].filter((k) => Object.hasOwn(raw, k)).map((k) => [k, raw[k]])) };
if (boxHere) {
const envWords = Object.entries(environment).map(([k, v]) => `${k}=${shellQuote(v)}`);
next.command = [box.shell, "-c", `${entry.runtime === "npm" ? `mkdir -p ${BOX_NPM_PREFIX} && ` : ""}exec ${envWords.length ? `env ${envWords.join(" ")} ` : ""}${argv.map(shellQuote).join(" ")}`];
diff --git a/apps/server/src/mcp-allow/mcp-policy.fixture.json b/apps/server/src/mcp-allow/mcp-policy.fixture.json
index 6f5db9d6..d85baab2 100644
--- a/apps/server/src/mcp-allow/mcp-policy.fixture.json
+++ b/apps/server/src/mcp-allow/mcp-policy.fixture.json
@@ -11,7 +11,7 @@
{"id": "playwright", "title": "Playwright (local pages)", "runtime": "npm", "package": "@playwright/mcp", "versions": ">=0.0.40", "pin": "0.0.83", "write_tools": ["browser_file_upload", "browser_evaluate", "browser_run_code", "browser_take_screenshot", "browser_pdf_save"], "rules": {"add_flags": ["--isolated", "--proxy-server=http://127.0.0.1:9", "--proxy-bypass=localhost,127.0.0.1,[::1],*.localhost"], "forbid_flags": ["--cdp-endpoint", "--cdp-header", "--extension", "--user-data-dir", "--storage-state", "--config", "--init-page", "--init-script", "--executable-path", "--proxy-server", "--proxy-bypass", "--allowed-hosts", "--allowed-origins", "--blocked-origins", "--output-dir", "--port", "--host"], "local_urls": true, "allow_flags": ["--isolated", "--headless", "--browser", "--device", "--viewport-size", "--user-agent", "--ignore-https-errors", "--no-sandbox", "--caps", "--image-responses", "--save-trace", "--save-session", "--timeout-action", "--timeout-navigation", "--test-id-attribute", "--snapshot-mode", "--console-level"], "flag_values": {"--browser": ["chrome", "chromium", "msedge", "chrome-for-testing"]}}, "bins": ["playwright-mcp"]},
{"id": "figma", "title": "Figma (desktop app)", "setup": "In the Figma desktop app, open a design file, switch to Dev Mode and turn on the MCP server (needs a Dev or Full seat).", "runtime": "remote", "package": "figma-dev-mode", "url": "http://127.0.0.1:3845/mcp", "oauth": false, "read_tools": ["get_design_context", "get_code", "get_variable_defs", "get_code_connect_map", "get_code_connect_suggestions", "get_screenshot", "get_image", "get_metadata", "get_figjam", "whoami"], "write_tools": ["add_code_connect_map", "send_code_connect_mappings", "create_design_system_rules", "generate_figma_design"]},
{"id": "figma", "title": "Figma (remote)", "setup": "Sign in once: omnirush mcp login figma (the desktop app: Sign in on the Figma card). The sign-in stays on this computer.", "runtime": "remote", "package": "figma-remote", "url": "https://mcp.figma.com/mcp", "oauth": true, "read_tools": ["get_design_context", "get_code", "get_variable_defs", "get_code_connect_map", "get_code_connect_suggestions", "get_screenshot", "get_image", "get_metadata", "get_figjam", "whoami"], "write_tools": ["add_code_connect_map", "send_code_connect_mappings", "create_design_system_rules", "generate_figma_design"]},
- {"id": "figma", "title": "Figma (API key)", "setup": "Set FIGMA_API_KEY (a Figma personal access token) in your environment before starting the app; never put it in a config file.", "runtime": "npm", "package": "figma-developer-mcp", "bins": ["figma-developer-mcp"], "versions": ">=0.13.2 <0.14", "pin": "0.13.2", "read_tools": ["get_figma_data"], "write_tools": ["download_figma_images"], "rules": {"secret_env": ["FIGMA_API_KEY", "FIGMA_OAUTH_TOKEN"], "add_flags": ["--stdio", "--no-telemetry"], "allow_flags": ["--stdio", "--no-telemetry", "--json", "--skip-image-downloads", "--image-dir"], "path_flags": ["--image-dir"], "path_inputs": ["localPath"]}}
+ {"id": "figma", "title": "Figma (API key)", "setup": "Set FIGMA_API_KEY (a Figma personal access token) in your environment before starting the app (on a Mac, open the desktop app from a terminal that has it); never put it in a config file.", "runtime": "npm", "package": "figma-developer-mcp", "bins": ["figma-developer-mcp"], "versions": ">=0.13.2 <0.14", "pin": "0.13.2", "read_tools": ["get_figma_data"], "write_tools": ["download_figma_images"], "rules": {"secret_env": ["FIGMA_API_KEY", "FIGMA_OAUTH_TOKEN"], "add_flags": ["--stdio", "--no-telemetry", "--env=/dev/null"], "allow_flags": ["--stdio", "--no-telemetry", "--json", "--skip-image-downloads", "--image-dir"], "path_flags": ["--image-dir"], "path_inputs": ["localPath"]}}
],
"deny": [
{"match": "@modelcontextprotocol/server-github", "reason": "The GitHub server works on your GitHub account."},
diff --git a/apps/server/src/server.ts b/apps/server/src/server.ts
index c8551128..441accd7 100644
--- a/apps/server/src/server.ts
+++ b/apps/server/src/server.ts
@@ -6424,7 +6424,9 @@ function assertEngineMcpRouteAllowed(config: ServerConfig, method: string, route
if (auth) {
// The one account sign-in the list allows: a remote server on it that signs in with OAuth (Figma's), by
// its id (the engine plugin keys it so); the engine keeps the tokens in its own store, not in a config.
- if (mcpSignInAllowed(config, decodeURIComponent(auth[1] ?? ""))) return;
+ let name = "";
+ try { name = decodeURIComponent(auth[1] ?? ""); } catch { refuseAccountLinkedMcp(); }
+ if (mcpSignInAllowed(config, name)) return;
refuseAccountLinkedMcp();
}
throw new ApiError(403, "engine_mcp_managed", "Add MCP servers in Settings > MCP: only the supported servers run.");