Skip to content

feat(api): prefer post-quantum TLS key exchange - #1248

Open
EhabY wants to merge 2 commits into
mainfrom
feat/post-quantum-key-exchange
Open

EhabY wants to merge 2 commits into
mainfrom
feat/post-quantum-key-exchange

Conversation

@EhabY

@EhabY EhabY commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

What

REST and WebSocket connections to the deployment now offer the post-quantum hybrid key exchange X25519MLKEM768, and fall back to classical groups when the server doesn't support it.

Why

How

src/api/keyExchange.ts provides two pieces, used at three call sites:

Path Change
WebSocket ecdhCurve in the ws options
REST an axios transport over follow-redirects that sets ecdhCurve, because axios has no per-request TLS options. It restores the redirect hooks axios skips for custom transports (maxRedirects and our cross-origin guard).
Our ProxyAgent ecdhCurve, for http.proxySupport on/off

An unsupported group name makes every TLS connection throw, so getEcdhCurve() tests the list once with tls.createSecureContext. If that fails, nothing is set.

On Electron 44+ this sends the same groups Electron already sends, so the handshake is unchanged. docs/ARCHITECTURE.md and the module note that it can be deleted once our minimum VS Code ships Electron 44.

follow-redirects (already installed through axios) is now a direct dependency.

Also fixed: a refused cross-origin redirect could be reported as a TLS client certificate error (and trigger coder.tlsCertRefreshCommand) when the target hostname spelled an alert name such as certificate_expired. The classifier now matches alert names only in TLS error shapes and ignores refused redirects, which covers REST and WebSocket.

Testing

test/unit/api/keyExchange.test.ts makes real HTTPS and WebSocket handshakes against a server that only accepts P-521. BoringSSL never offers P-521 by default, so a connection succeeds only if our option reaches tls.connect. The tests cover REST (with a redirect), WebSocket, and our own agent. Certificates are verified with the fixture CA. A cross-origin redirect test runs with the transport always active. Removing the wiring, the restored redirect guard, or the redirect check in the classifier each fails a test.

Manual check on VS Code 1.149 / Electron 43, using VS Code's real proxy patch: axios negotiated x25519 before this change and X25519MLKEM768 after. Electron 37.6 behaves the same, and Electron 44 already negotiates X25519MLKEM768.

Out of scope: the SSH tunnel, which runs through the Go CLI.

Decisions
  • Custom transport plus an upstream issue over changing tls.DEFAULT_ECDH_CURVE, which would affect every extension in the extension host.
  • Startup check, no setting: on unless the runtime rejects the list.
  • Group list X25519MLKEM768:X25519:P-256:P-384 matches Electron 44's default.
  • maxRedirects: 0 keeps axios's native transport and the runtime default. Nothing sets it today.

Generated by Coder Agents on behalf of @EhabY.

Comment thread test/unit/api/keyExchange.test.ts Fixed
Comment thread test/unit/api/keyExchange.test.ts Fixed
Comment thread test/unit/api/keyExchange.test.ts Fixed
Comment thread test/unit/api/keyExchange.test.ts Fixed
Offer X25519MLKEM768 with classical fallback on REST and WebSocket
connections to the deployment. Electron before 44 does not offer it by
default, and VS Code's default proxy support replaces our agent, so the
groups go on each request: in ws options and an axios transport over
follow-redirects. The group list is probed once because an unsupported
name breaks every TLS connection.
@EhabY
EhabY force-pushed the feat/post-quantum-key-exchange branch from 9ea43a2 to e3c1ed8 Compare December 4, 2026 11:18
@EhabY
EhabY marked this pull request as ready for review December 4, 2026 11:19
A refused cross-origin redirect carries the target hostname in its
message, and the client certificate classifier matched alert names
anywhere in a message. Match alert names only in TLS error shapes and
skip errors caused by a refused redirect.

The key exchange transport reads axios options as own properties, and a
test covers its cross-origin redirect guard with the transport active.
@EhabY
EhabY force-pushed the feat/post-quantum-key-exchange branch from 9af4655 to 911cf23 Compare December 4, 2026 15:28
Lisa-Fiander
Lisa-Fiander previously approved these changes Dec 4, 2026

@Lisa-Fiander Lisa-Fiander left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good!

@Lisa-Fiander
Lisa-Fiander dismissed their stale review December 4, 2026 15:36

need second opinion

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants