Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@
from published versions since it shows up in the VS Code extension changelog
tab and is confusing to users. Add it back between releases if needed. -->

## Unreleased

### Added

- Connections to the Coder deployment prefer the post-quantum hybrid key
exchange `X25519MLKEM768` when VS Code and the deployment support it, and fall
back to classical key exchange otherwise.

### Fixed

- When the deployment redirects to another URL, the extension reports the
redirect instead of mistaking it for a TLS client certificate error.

## [v1.18.4](https://github.com/coder/vscode-coder/releases/tag/v1.18.4) 2026-12-03

### Added
Expand Down
9 changes: 9 additions & 0 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ Worth knowing:
`windowsAcl.native.test.ts` drives the real `icacls.exe`, `whoami.exe`, and
OpenSSH. Run it unelevated as well as in CI to catch privilege assumptions.

## TLS key exchange

REST and WebSocket connections to the deployment offer the post-quantum hybrid
group `X25519MLKEM768` (`src/api/keyExchange.ts`). Electron before 44 does not
offer it by default, and VS Code's proxy support replaces our agent, so the
groups are set on each request. A network that drops the larger ClientHello
this sends fails with a generic connection error, as Chrome would. Remove the
module once the minimum supported VS Code ships Electron 44.

## Other features

The extension provides several sidebar panels:
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@
"date-fns": "catalog:",
"fflate": "^0.8.3",
"find-process": "^2.1.1",
"follow-redirects": "^1.16.3",
"jsonc-parser": "^3.3.1",
"openpgp": "^6.3.3",
"pretty-bytes": "^7.2.0",
Expand All @@ -868,6 +869,7 @@
"@testing-library/react": "^16.3.3",
"@testing-library/user-event": "catalog:",
"@tsconfig/node22": "^22.0.7",
"@types/follow-redirects": "^1.14.4",
"@types/mocha": "^10.0.10",
"@types/node": "^22.20.7",
"@types/proper-lockfile": "^4.1.4",
Expand Down
13 changes: 13 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/api/coderApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {

import { getRefreshCommand, refreshCertificates } from "./certificateRefresh";
import { createHttpAgent } from "./httpAgent";
import { createKeyExchangeTransport, getEcdhCurve } from "./keyExchange";
import {
parseApiResponse,
VALIDATED_RESPONSES,
Expand Down Expand Up @@ -451,6 +452,8 @@ export class CoderApi extends Api implements vscode.Disposable {
options: {
...configs.options,
agent: httpAgent,
// On the request too: VS Code's proxy support replaces the agent.
ecdhCurve: getEcdhCurve(),
followRedirects: true,
// A stalled handshake would otherwise never error or retry.
handshakeTimeout: DEFAULT_REQUEST_TIMEOUT_MS,
Expand Down Expand Up @@ -582,6 +585,7 @@ function setupInterceptors(
config.httpsAgent = agent;
config.httpAgent = agent;
config.proxy = false;
config.transport = createKeyExchangeTransport(config, getEcdhCurve());

return config;
});
Expand Down
2 changes: 2 additions & 0 deletions src/api/httpAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { type WorkspaceConfiguration } from "vscode";
import { expandPath } from "../common/fs";
import { LocalProxySettings, type LocalProxySetting } from "../settings/proxy";

import { getEcdhCurve } from "./keyExchange";
import { getProxyForUrl, joinNoProxy } from "./proxy";

/** Whether requests carry a TLS client certificate (mTLS). */
Expand Down Expand Up @@ -73,6 +74,7 @@ export async function createHttpAgent(
key,
ca,
servername: altHost === "" ? undefined : altHost,
ecdhCurve: getEcdhCurve(),
// TLS verification is disabled if either:
// - http.proxyStrictSSL is false (VS Code's proxy SSL setting)
// - coder.insecure is true (backward compatible override for Coder server)
Expand Down
81 changes: 81 additions & 0 deletions src/api/keyExchange.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import followRedirects, { type FollowOptions } from "follow-redirects";
import tls from "node:tls";

import type { AxiosRequestConfig } from "axios";
import type { IncomingMessage } from "node:http";
import type { RequestOptions } from "node:https";

/**
* Electron 44+ offers this list by default. Delete this module once the
* minimum supported VS Code ships Electron 44.
*/
const PREFERRED_ECDH_CURVE = "X25519MLKEM768:X25519:P-256:P-384";

/** The cached probe result; unset until `getEcdhCurve` first runs. */
let probed: { ecdhCurve: string | undefined } | undefined;

/**
* The TLS key exchange groups to offer, or undefined for the runtime default.
* An unsupported group name makes every TLS connection throw, so the list is
* probed once before it is used.
*/
export function getEcdhCurve(): string | undefined {
if (!probed) {
try {
tls.createSecureContext({ ecdhCurve: PREFERRED_ECDH_CURVE });
probed = { ecdhCurve: PREFERRED_ECDH_CURVE };
} catch {
probed = { ecdhCurve: undefined };
}
}
return probed.ecdhCurve;
}

type TransportOptions = RequestOptions &
FollowOptions<RequestOptions> & {
beforeRedirects: Record<string, AxiosRequestConfig["beforeRedirect"]>;
};

/**
* An axios transport that puts `ecdhCurve` on each request, since axios has
* no per-request TLS options and VS Code's proxy support replaces our agent.
* Returns undefined, keeping the axios transport, when there is nothing to add.
*/
export function createKeyExchangeTransport(
config: Pick<AxiosRequestConfig, "beforeRedirect" | "maxRedirects">,
ecdhCurve: string | undefined,
) {
// Without redirects axios uses its native transport, which this would replace.
if (!ecdhCurve || config.maxRedirects === 0) {
return undefined;
}
return {
request(
options: TransportOptions,
callback: (res: IncomingMessage) => void,
) {
options.ecdhCurve = ecdhCurve;
// Axios wires these into follow-redirects only for its own transport.
// It also wires `auth` and `sensitiveHeaders`, which we don't use;
// mirror them here if that changes.
const maxRedirects = own(config, "maxRedirects");
if (maxRedirects) {
options.maxRedirects = maxRedirects;
}
options.beforeRedirects.config = own(config, "beforeRedirect");
const scheme =
options.protocol === "https:"
? followRedirects.https
: followRedirects.http;
return scheme.request(options, callback);
},
};
}

/** Reads an own property only, as axios does, so a polluted prototype can't supply it. */
function own<K extends keyof AxiosRequestConfig>(
config: Pick<AxiosRequestConfig, K>,
key: K,
): AxiosRequestConfig[K] | undefined {
return Object.hasOwn(config, key) ? config[key] : undefined;
}
21 changes: 16 additions & 5 deletions src/error/clientCertificateError.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as vscode from "vscode";

import { CertificateError } from "./certificateError";
import { CrossOriginRedirectError } from "./crossOriginRedirectError";
import { toError } from "./normalize";

/**
Expand Down Expand Up @@ -50,12 +51,18 @@ function isClientCertAlert(code: number): code is CLIENT_CERT_ALERT {
}

/**
* Patterns to match SSL alert types in error messages (case-insensitive).
* Alert names as OpenSSL and BoringSSL render them, such as
* `SSLV3_ALERT_CERTIFICATE_EXPIRED` or `tlsv1 alert unknown ca`.
*/
const ALERT_PATTERNS: ReadonlyArray<[string, CLIENT_CERT_ALERT]> =
const ALERT_PATTERNS: ReadonlyArray<[RegExp, CLIENT_CERT_ALERT]> =
Object.entries(CLIENT_CERT_ALERT)
.filter(isNumericEnumEntry)
.map(([name, code]) => [name.toLowerCase(), code]);
.map(([name, code]) => [
new RegExp(
`(?:sslv3|tlsv1|ssl)[ _]alert[ _]${name.toLowerCase().replaceAll("_", "[ _]")}`,
),
code,
]);

/**
* Alert codes that may be recoverable by refreshing the certificate.
Expand Down Expand Up @@ -134,14 +141,18 @@ export class ClientCertificateError extends CertificateError {
* Returns undefined if the error is not a recognized client certificate error.
*/
private static detectAlertCode(err: unknown): CLIENT_CERT_ALERT | undefined {
// A refused redirect's message holds a deployment-chosen hostname, which
// can spell an alert name.
if (CrossOriginRedirectError.find(err)) {
return undefined;
}
const message = this.extractErrorMessage(err).toLowerCase();
if (!message) {
return undefined;
}

// Check for alert patterns (case-insensitive via lowercase)
for (const [pattern, alertCode] of ALERT_PATTERNS) {
if (message.includes(pattern)) {
if (pattern.test(message)) {
return alertCode;
}
}
Expand Down
10 changes: 10 additions & 0 deletions test/unit/api/coderApi.origin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ describe("CoderApi origin scoping", () => {
expect(moved.requests).toHaveLength(0);
});

it("refuses a redirect to a host named like a TLS alert", async () => {
const deployment = await startRecordingServer(
() => "https://sslv3_alert_certificate_expired.example.com/api",
);

await expect(get(deployment.origin, "/api")).rejects.toBeInstanceOf(
CrossOriginRedirectError,
);
});

it("sends no auth headers to another origin", async () => {
const deployment = await startRecordingServer();
const other = await startRecordingServer();
Expand Down
5 changes: 5 additions & 0 deletions test/unit/api/coderApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from "@/api/certificateRefresh";
import { CoderApi, DEFAULT_REQUEST_TIMEOUT_MS } from "@/api/coderApi";
import { createHttpAgent } from "@/api/httpAgent";
import { getEcdhCurve } from "@/api/keyExchange";
import {
InvalidApiResponseError,
VALIDATED_RESPONSES,
Expand Down Expand Up @@ -515,6 +516,7 @@ describe("CoderApi", () => {

expect(Ws).toHaveBeenCalledWith(wsUrl, undefined, {
agent: mockAgent,
ecdhCurve: getEcdhCurve(),
followRedirects: true,
handshakeTimeout: DEFAULT_REQUEST_TIMEOUT_MS,
headers: {
Expand All @@ -531,6 +533,7 @@ describe("CoderApi", () => {

expect(Ws).toHaveBeenCalledWith(wsUrl, undefined, {
agent: undefined,
ecdhCurve: getEcdhCurve(),
followRedirects: true,
handshakeTimeout: DEFAULT_REQUEST_TIMEOUT_MS,
headers: {
Expand All @@ -549,6 +552,7 @@ describe("CoderApi", () => {

expect(Ws).toHaveBeenCalledWith(wsUrl, undefined, {
agent: undefined,
ecdhCurve: getEcdhCurve(),
followRedirects: true,
handshakeTimeout: DEFAULT_REQUEST_TIMEOUT_MS,
headers: {
Expand All @@ -571,6 +575,7 @@ describe("CoderApi", () => {

expect(Ws).toHaveBeenCalledWith(wsUrl, undefined, {
agent: undefined,
ecdhCurve: getEcdhCurve(),
followRedirects: true,
handshakeTimeout: DEFAULT_REQUEST_TIMEOUT_MS,
headers: {
Expand Down
Loading
Loading