Repository navigation
fix(gateway-client): verify TLS pin before websocket upgrade - #131435
Merged
Merged
Conversation
Reuse the common request setup for auxiliary streams so managed connections can attach after the connection event has already completed. Preserve stream endpoint policy and ordering, and cover direct and managed routes with real-socket tests.
Contributor
|
🦞👀 Pull request received. I will update this pull request when review starts. |
steipete
marked this pull request as ready for review
August 28, 2026 02:37
Contributor
Author
|
Merged via squash.
|
This was referenced Aug 28, 2026
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Aug 28, 2026
…w#131435) * fix(gateway-client): verify TLS pin before websocket upgrade * fix(node-host): share websocket request preparation Reuse the common request setup for auxiliary streams so managed connections can attach after the connection event has already completed. Preserve stream endpoint policy and ordering, and cover direct and managed routes with real-socket tests.
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.
What Problem This Solves
When connecting to a Gateway with TLS certificate pinning, the client validated the pin only after the WebSocket opened. Because pinning sets
rejectUnauthorized: false(Node skipscheckServerIdentityonce chain verification has already failed), the HTTP Upgrade request — including any configured edge-auth headers — was written to the destination socket before the pin was checked. A wrong or self-signed endpoint therefore received request bytes (and edge-auth header material) before the mismatch aborted the connection.Why This Change Was Made
The pin must be verified on the actual destination TLS socket before any HTTP bytes leave the client. The fix moves validation into the existing
wsfinishRequestseam: perform the TLS handshake, verify the SHA-256 pin on the secure socket, and only then callrequest.end().Expectheaders are withheld from request construction (Node can flush them early). The same gate covers managed CONNECT proxy sockets (which arrive already-secure via@openclaw/proxyline). A typedGatewayWebSocketTlsPinErrorpreserves the mismatch identity across the request→WebSocket error boundary, and worker admission maps it to the existing terminal endpoint error so a pin mismatch never becomes a retry loop; ordinary pre-open failures stay retryable. An open event now means the transport already validated, so the post-open check inclient.tsis deleted — one canonical flow.A deep-context review found and fixed a second instance of the same flaw:
src/node-host/node-stream-transport.ts(desktop/portal streams) had its own request finisher waiting unconditionally forsecureConnect, so managed-CONNECT streams leaked the same pre-pin bytes. It now shares the extractedapplyGatewayWebSocketTlsPinhelper.Contracts verified against installed sources:
ws8.21.3 (request construction/error forwarding/redirect defaults),@openclaw/proxyline0.3.7 (CONNECT socket delivered only aftersecureConnect), and Node v26.5.0 + v24.19.0 built-in_http_client/_http_outgoing/internal/tls/wrap(Expect flush timing, chain-check/callback ordering).User Impact
Pinned Gateway connections that fail the pin now send zero application bytes to the untrusted endpoint — no edge-auth headers, no Upgrade. Correct-pin, no-pin (CA-validated), and trusted-CA connections behave exactly as before. No config, dependency, schema, or protocol change.
Evidence
client.watchdog.test.tsinline HTTPS setup, now covered by the stronger direct/proxy TLS suite.