security: harden pipe auth, CDP proxy, markdown XSS, and webview#45
Open
foschmitz wants to merge 1 commit into
Open
security: harden pipe auth, CDP proxy, markdown XSS, and webview#45foschmitz wants to merge 1 commit into
foschmitz wants to merge 1 commit into
Conversation
Addresses the critical/high findings from the security review: - Pipe auth (amirlehmam#1): privileged V2 methods now require a per-instance token (crypto.randomBytes, 0600 file in APPDATA, timing-safe compare). Public telemetry methods stay open via an allowlist so detection/hooks keep working. Token injected into spawned shells as WMUX_PIPE_TOKEN; CLI and hook clients read it from env or the token file. - CDP proxy (amirlehmam#2): reject DNS-rebinding via a loopback-only Host allowlist (HTTP 403 + WS verifyClient) AND a browser-Origin guard on the WS upgrade (WebSockets bypass CORS, so a passing Host alone lets a malicious page open ws://127.0.0.1:9222 and reach Runtime.evaluate). Absent Origin is allowed so chrome-devtools-mcp/puppeteer/native ws clients still connect. - Markdown XSS (amirlehmam#3): sanitize marked output with DOMPurify before dangerouslySetInnerHTML in the privileged renderer. - markdown.load_file: extension allowlist + 5MB cap + isFile check so a pipe caller can't slurp arbitrary secrets into the viewer. - Webview hardening (amirlehmam#9): central web-contents-created handler strips preload/nodeIntegration from webviews, routes window.open to the OS browser, and blocks the main window from navigating off its own UI. Tests: pipe-server token auth (9) + new cdp-proxy host/origin guard (9).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses the critical/high findings from a security review of the IPC pipe, CDP proxy, markdown rendering, and webview surfaces. No behavior change for normal use; the only externally-visible effect is that privileged pipe (V2) calls and direct CDP WebSocket connections from web origins are now rejected.
Findings fixed
#1 — Unauthenticated local RCE via named pipe (Critical)
Any local process could call privileged V2 methods (
agent.spawn,browser.eval,markdown.load_file, workspace/pane mutation). Now:crypto.randomBytes(32), persisted0600under the instance APPDATA dir, compared withcrypto.timingSafeEqual.system.identify,system.capabilities,hook.event,agent.activity) stays open so detection, shell hooks, and agent telemetry keep working — and any new method is locked by default.WMUX_PIPE_TOKEN; thewmuxCLI and hook client read it from env or the token file.#2 — CDP proxy reachable from web origins (Critical)
The CDP proxy exposes
Runtime.evaluate(arbitrary JS in the webview). Loopback binding alone is insufficient:Host(403 /verifyClientreject).ws://127.0.0.1:9222(validHost) and drive the debugger. We now also validateOriginon the WS upgrade and reject any web/file origin. AbsentOriginis allowed sochrome-devtools-mcp/puppeteer-core/nativewsclients still connect (mirrors Chrome's--remote-allow-origins).#3 — Markdown XSS (High)
Markdown can arrive from untrusted CLI/pipe/agent/file sources and was injected via
dangerouslySetInnerHTMLin the privileged renderer. Now sanitized with DOMPurify (forbidsjavascript:URIs, event handlers,style/form controls).markdown.load_file path abuse
Even with a valid token, the loader now enforces an extension allowlist (
.md/.markdown/.mdx/.txt/.text/.rst), a 5MB cap, and anisFilecheck — so it can't be used to slurp secrets (id_rsa,.env, …) into the viewer.#9 — Webview hardening (Low/defense-in-depth)
Central
web-contents-createdhandler: stripspreload/nodeIntegrationfrom attached webviews (enforcescontextIsolation), routeswindow.opento the OS browser, and blocks the main window from navigating off its own UI (localhost/file://).Tests
tests/unit/pipe-server.test.ts: token enforcement (reject without/with wrong token, accept correct token, public methods open, V1 still works) — 9 tests.tests/unit/cdp-proxy.test.ts(new): Host allowlist (loopback/IPv6/rebind/non-loopback) + Origin guard (absent/devtools allowed, web origins rejected) — 9 tests.pty-manager.test.tsfails only because the node-pty native module isn't built on this Linux dev box — pre-existing/environmental, fails identically onmaster.)Notes for reviewer
chrome-devtools-mcpconnects via--browserUrl=http://127.0.0.1:9222(set inclaude-context.ts) and can't send a custom token.