Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(agent-runtime): skip expired system trust anchors

vastsa8c267ab243ee
diff --cc docs/adr/provider-system-certificates.md
index 9db7fc4df,9db7fc4df..85e218cae
--- a/docs/adr/provider-system-certificates.md
+++ b/docs/adr/provider-system-certificates.md
@@@ -32,10 -32,10 +32,12 @@@ sidecar merges its bundled roots, the i
and the system-store certificates into the default CA set at startup
(`tls.setDefaultCACertificates`, agent-runtime `system-ca`). Either way the
effective trust set is the same: bundled roots, system roots, and an inherited
--extra-CA file, deduplicated by content. Certificate chain, expiration and
--hostname validation remain enabled. The app neither installs roots nor exports
--a certificate bundle. The operating system's existing trust policy is the
--authority for local roots.
++extra-CA file, deduplicated by content. Certificates already expired in the OS
++store are omitted from the additive merge because system stores can retain
++stale entries; bundled roots and the inherited extra-CA set remain unchanged.
++Certificate chain, expiration and hostname validation remain enabled. The app
++neither installs roots nor exports a certificate bundle. The operating
++system's existing trust policy is the authority for local roots.
This applies to the desktop sidecar's default Node TLS clients, including the
direct, HTTP proxy and SOCKS provider transports. It is a process-level default,
diff --cc docs/spec/03-runtime/02-agent-runtime.md
index 047bb8b8e,34f3a0a7e..4ed5c2491
--- a/docs/spec/03-runtime/02-agent-runtime.md
+++ b/docs/spec/03-runtime/02-agent-runtime.md
@@@ -1851,9 -1851,9 +1851,11 @@@ browseable
### Provider certificate trust (issue #714)
The desktop sidecar's effective trust set is the union of Node's bundled
--roots, the inherited `NODE_EXTRA_CA_CERTS` set, and the OS trust store, with
--chain and hostname validation on. On Windows and Linux the launcher passes
--Node's `--use-system-ca` to obtain the system roots. On macOS the Electron
++roots, the inherited `NODE_EXTRA_CA_CERTS` set, and non-expired entries from
++the OS trust store, with chain and hostname validation on. Expired entries in
++the OS store are omitted because platform stores may retain stale certificates;
++bundled and `NODE_EXTRA_CA_CERTS` entries are unchanged. On Windows and Linux
++the launcher passes Node's `--use-system-ca` to obtain the system roots. On macOS the Electron
build applies that flag by replacing the bundled roots instead of adding them
and its system enumeration misses public anchors (issue #1187), so the
launcher omits the flag and the sidecar merges the three sets into the default
diff --cc docs/spec/06-delivery/04-e2e-test-plan.md
index 3968d43a7,c6989e987..c79354cce
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@@ -17553,7 -17436,7 +17553,9 @@@ the latest destination. These assertion
desktop sidecar and submit a chat prompt against an untrusted localhost
certificate. Relaunch with its CA in `NODE_EXTRA_CA_CERTS`, then request the
same certificate through a hostname absent from its SAN.
--- **Expected:** The child's default CA set includes system roots and extra CAs.
++- **Expected:** The child's default CA set includes every non-expired system
++ root and extra CAs, while expired system-store entries are omitted. Bundled
++ roots and inherited extra CAs remain available.
The first request fails once with a non-retriable certificate error and no
retry status; the trusted request returns text; the hostname mismatch still
fails once. TLS and hostname verification remain enabled.
diff --cc docs/zh-CN/spec/03-runtime/02-agent-runtime.md
index 610665e4c,67ad9cf89..fbee6acae
--- a/docs/zh-CN/spec/03-runtime/02-agent-runtime.md
+++ b/docs/zh-CN/spec/03-runtime/02-agent-runtime.md
@@@ -1249,7 -1249,7 +1249,8 @@@ provider/model 目录发现超出当前
### Provider certificate trust(issue #714)
桌面 sidecar 使用 Node 的 `--use-system-ca` 启动,同时保留内置根证书和继承的
--`NODE_EXTRA_CA_CERTS`。它使用操作系统信任库,但不会关闭证书链或主机名校验。
++`NODE_EXTRA_CA_CERTS`,并排除操作系统信任库中已过期的证书,因为平台证书库可能保留
++过期条目。内置根证书和 `NODE_EXTRA_CA_CERTS` 不受影响,也不会关闭证书链或主机名校验。
更新本地信任库或额外 CA 启动环境后,需要重启桌面应用。无头 pi-host 启动行为以及
System/Direct/Custom 代理路由保持不变。
diff --cc docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index d48f8dfa1,20fdd2d13..5551fc96d
--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
@@@ -9240,7 -9186,7 +9240,8 @@@ Follow the [current S3 acceptance scena
- **步骤:** 运行 `node scripts/e2e-provider-certificates.mjs`。启动真实桌面
sidecar,使用不受信任的 localhost 证书提交聊天提示。再将其 CA 放入
`NODE_EXTRA_CA_CERTS` 后重启,并通过 SAN 中不存在的主机名请求同一证书。
--- **预期:** 子进程默认 CA 集合包含系统根证书和额外 CA。首次请求只失败一次,
++- **预期:** 子进程默认 CA 集合包含所有未过期的系统根证书和额外 CA,排除系统证书库中
++ 已过期的条目。首次请求只失败一次,
返回不可重试的证书错误且没有重试状态;信任 CA 后请求返回文本;主机名不匹配
仍只失败一次。TLS 和主机名校验始终保持启用。
- **UI:** 运行 `node scripts/e2e-provider-certificate-ui.mjs`,在隔离 Chromium
diff --cc packages/agent-runtime/src/system-ca.test.ts
index f2119849f,0749ff3e4..252c96fdc
--- a/packages/agent-runtime/src/system-ca.test.ts
+++ b/packages/agent-runtime/src/system-ca.test.ts
@@@ -1,7 -1,7 +1,16 @@@
import { X509Certificate } from "node:crypto";
++import { readFileSync } from "node:fs";
import * as tls from "node:tls";
import { expect, it } from "vitest";
--import { applyAdditiveDefaultCaCertificates } from "./system-ca.js";
++import {
++ applyAdditiveDefaultCaCertificates,
++ filterUnexpiredSystemCertificates,
++} from "./system-ca.js";
++
++const certificateFixture = readFileSync(
++ new URL("../../../scripts/e2e/fixtures/certificates/localhost-cert.pem", import.meta.url),
++ "utf8",
++);
// `setDefaultCACertificates` re-serializes its input, so later reads return
// strings that differ in encoding whitespace; identity is the certificate
@@@ -28,3 -28,30 +37,47 @@@ it("applyAdditiveDefaultCaCertificates
const twice = fingerprints(tls.getCACertificates("default")).size;
expect(twice).toBe(once);
});
+
+ it("applyAdditiveDefaultCaCertificates never adds an already expired system anchor", () => {
+ const now = Date.now();
+ const bundled = fingerprints(tls.getCACertificates("bundled"));
+ const expiredSystem = tls
+ .getCACertificates("system")
+ .filter((pem) => {
+ try {
+ return new Date(new X509Certificate(pem).validTo).getTime() <= now;
+ } catch {
+ return false;
+ }
+ })
+ .map((pem) => new X509Certificate(pem).fingerprint256);
+
+ applyAdditiveDefaultCaCertificates();
+
+ const after = fingerprints(tls.getCACertificates("default"));
+ for (const fingerprint of expiredSystem) {
+ // A bundled root that happens to be expired stays: the bundled set is the
+ // runtime's own baseline. Only the system merge is filtered, because a
+ // stale cache entry there can act as the anchor for a live chain.
+ if (bundled.has(fingerprint)) continue;
+ expect(after.has(fingerprint)).toBe(false);
+ }
+ });
+
++it("filters expired system certificates while retaining valid and unparseable entries", () => {
++ const expiresAt = Date.parse(new X509Certificate(certificateFixture).validTo);
++ const unparseable = "unparseable certificate";
++
++ expect(
++ filterUnexpiredSystemCertificates(
++ [certificateFixture, unparseable],
++ expiresAt - 1,
++ ),
++ ).toEqual([certificateFixture, unparseable]);
++ expect(
++ filterUnexpiredSystemCertificates(
++ [certificateFixture, unparseable],
++ expiresAt,
++ ),
++ ).toEqual([unparseable]);
++});
diff --cc packages/agent-runtime/src/system-ca.ts
index 6dcebe3fe,12e0a070d..f6323990c
--- a/packages/agent-runtime/src/system-ca.ts
+++ b/packages/agent-runtime/src/system-ca.ts
@@@ -18,7 -19,25 +19,32 @@@ import * as tls from "node:tls"
* and an inherited `NODE_EXTRA_CA_CERTS` still lands in the `extra` set.
* Certificate chain, expiration and hostname validation are untouched — this
* widens the trust set, it never disables verification.
+ *
+ * The OS stores are a cache, so they keep entries that already expired: Windows
+ * still lists Let's Encrypt's `ISRG Root X2` and `R3` with a 2025-09-15 expiry
+ * long after the fact. Merging one of those makes OpenSSL accept an expired
+ * certificate as the anchor for any chain that names it as issuer, and the
+ * handshake then fails with `CERT_HAS_EXPIRED` even though the server's own
+ * chain is valid and reaches a current root. An anchor that has already
+ * expired can verify nothing, so it is never merged.
*/
+ function isExpiredCertificate(pem: string, now: number): boolean {
+ try {
+ return new Date(new X509Certificate(pem).validTo).getTime() <= now;
+ } catch {
+ // Unparseable input is left to the runtime: dropping it would silently
+ // narrow the trust set this function exists to widen.
+ return false;
+ }
+ }
+
++export function filterUnexpiredSystemCertificates(
++ certificates: readonly string[],
++ now: number,
++): string[] {
++ return certificates.filter((certificate) => !isExpiredCertificate(certificate, now));
++}
++
export function applyAdditiveDefaultCaCertificates(): void {
if (typeof tls.setDefaultCACertificates !== "function") return;
const bundled = tls.getCACertificates("bundled");
@@@ -27,11 -46,12 +53,10 @@@
if (system.length === 0) return;
const seen = new Set(bundled.map((cert) => cert));
const merged = [...bundled, ...extra.filter((cert) => !seen.has(cert))];
- const now = Date.now();
-- for (const cert of system) {
- if (!seen.has(cert)) {
- seen.add(cert);
- merged.push(cert);
- }
++ for (const cert of filterUnexpiredSystemCertificates(system, Date.now())) {
+ if (seen.has(cert)) continue;
- if (isExpiredCertificate(cert, now)) continue;
+ seen.add(cert);
+ merged.push(cert);
}
try {
tls.setDefaultCACertificates(merged);