Repository navigation
Web Terminal: accept cross-origin postMessage from clickhouse.com/cloud - #105191
Conversation
The web terminal page exchanges postMessage with its embedding parent for
three things: receiving credentials, receiving refit requests, and
notifying the parent on Escape / WebSocket close. Both directions
previously required the parent to be same-origin: the inbound check
rejected anything where e.origin !== window.location.origin, and the
outbound calls used window.location.origin as targetOrigin, which the
browser silently drops when the parent is on a different origin.
That makes the terminal effectively non-embeddable from clickhouse.com
or any other site outside play.clickhouse.com. Loosen the policy:
- Inbound: accept messages from same-origin and from any https origin
whose hostname is (or is a subdomain of) clickhouse.com /
clickhouse.cloud.
- Outbound: remember the parent origin from the first valid message
(including an optional 'webterminal-hello' handshake) and post back
to that exact origin, so the browser delivers it.
Credentials and other messages from untrusted origins are still
rejected. Apex domains are matched explicitly; URL parsing anchors on
hostname so suffixes like evil.clickhouse.com.attacker.tld are not
matched.
|
Workflow [PR], commit [23fbd3c] Summary: ✅ AI ReviewSummaryThis PR updates Final VerdictStatus: ✅ Approve |
Reviewer pointed out that validating `e.origin` alone allows any window from a trusted origin (e.g. one obtained via `window.open` by the parent) to drive `webterminal-credentials` and `webterminal-refit`. Tighten the check so only messages from the embedding parent are accepted. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
@groeneai, please investigate the failure: |
Summary
The web terminal (
programs/server/webterminal.html) usespostMessagefor three things:webterminal-credentialsandwebterminal-refitfrom the parentwebterminal-escape(on Escape key) andwebterminal-closed(on WebSocket close) to the parentBoth directions previously assumed the parent is same-origin:
That second arg is the target origin — the browser drops the post if the parent's actual origin doesn't equal it. So when the terminal is embedded from a different origin (e.g.
https://clickhouse.comembeddinghttps://play.clickhouse.com/webterminal), inbound is rejected and outbound is silently dropped. The terminal effectively can't be embedded outsideplay.clickhouse.com.Changes
clickhouse.com,clickhouse.cloud, or a subdomain of either. Apex domains are matched by equality; subdomains byendsWith('.clickhouse.com')/endsWith('.clickhouse.cloud'). URL parsing anchors on hostname so suffixes likeevil.clickhouse.com.attacker.tldare not matched.webterminal-hellohandshake), and post back to that exact origin. If we've never heard from a trusted parent, outbound posts are skipped rather than leaked to'*'.Why an allowlist instead of
'*''*'would let any site iframe the terminal and feed it forgedwebterminal-credentials. The user typing their own credentials into an attacker-controlled embed is "their problem," but accepting credentials only from origins ClickHouse controls is a cheap and clear improvement.Compatibility
play.htmlflow) keep working — same-origin is the first branch in the trust check, and the outbound target is still the same string.*.clickhouse.com/*.clickhouse.cloudnow work. Other origins are still rejected.Test plan
/playon a server withallow_experimental_webterminal=1, press the terminal toggle, type a query, press Escape — terminal hides as before.https://clickhouse.com(marketing site PR: https://github.com/ClickHouse/marketing-website/pull/1448), open the dropdown terminal, verifywebterminal-refitis applied (terminal sizes correctly), and Escape closes the panel.postMessageis ignored both ways (devtools console shows no credential acceptance).Changelog category (leave one):
Changelog entry:
The experimental web terminal (
allow_experimental_webterminal) can now be embedded cross-origin fromclickhouse.com,clickhouse.cloud, and their subdomains. Previously,postMessagefrom any non-same-origin parent was rejected on inbound and silently dropped on outbound, making the terminal effectively un-embeddable outsideplay.clickhouse.com. The accepted origin list is an explicit allowlist (https only, hostname-anchored), so untrusted origins are still rejected.Documentation entry for user-facing changes