Skip to content

fix(net): every HTTPS request and wss socket trusts the system certificate store's roots - #1124

Merged
Hona merged 13 commits into
devfrom
net/os-certificate-trust
Nov 27, 2026
Merged

Hona merged 13 commits into
devfrom
net/os-certificate-trust

Conversation

@Hona

@Hona Hona commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Every HTTPS request and wss:// socket of the app trusts the roots in the operating system's certificate store as well as the compiled-in list, as the official desktop app (Chromium) does. The updater keeps the compiled-in list alone as a fallback.

Problem

Behind a network that inspects TLS with its own root installed in the system certificate store (common on company PCs), most of the app's own requests fail with an unknown-issuer error:

  • The update check and download, so no update is ever offered.
  • A remote server's requests, event stream, MCP socket, browser stream tunnel socket, and the terminal socket.
  • Pairing, plugin requests, Hex, web pictures (markdown images, favicons) and the office font download.

The cause is ureq's default: TlsConfig::default() uses RootCerts::WebPki, the Mozilla list compiled into the binary (ureq 3.5.0 src/tls/mod.rs:369-375). The WebSockets use tungstenite's rustls-tls-webpki-roots, the same compiled-in list.

The pane's pages, the official app's page and its updater go through Chromium, which uses the system store.

Change

  • New crate net-trust: one root set for the process, the compiled-in roots (webpki-root-certs) plus the system store's (rustls-native-certs), checked by webpki.

    • agent_config(): a ureq agent configuration with RootCerts::Specific of that set.
    • agent_config_for(base): the same, except a plain http:// base (the local server) gets no TLS settings, so it never reads the store.
    • tls_config(): the TLS settings on their own.
    • rustls_client_config(): a rustls configuration with the same roots, made once, for a socket's own TLS.
    • builtin_agent_config() and is_certificate_refusal(): the updater's fallback.
    • On wasm32, the agent configurations are the browser shim's, since the browser checks certificates itself.
  • The store is read once per process, on first use, off the launch path: a OnceLock filled the first time a TLS configuration is made. The server client builds its agent lazily (Server::agent()), so a launch against the local server reads no store. The app logs net-trust: read N roots from the system store in X us.

  • No online revocation: webpki checks the chain, names and validity time only. Nothing fetches OCSP or CRLs, so no handshake can wait on a revocation server that a network drops.

  • Every ureq agent starts from net_trust: 23 call sites in 18 files (including sidecar probe and PTY handoff via agent_config_for).

  • All three WebSockets use client_tls_with_config with the shared rustls configuration for wss://: the MCP client in opencode-kit, the browser stream tunnel client in opencode-kit, and the persistent terminal, which had used tungstenite::connect. A ws:// socket builds no TLS configuration.

  • The updater's fallback: when the update feed or the download is refused in the TLS handshake, the updater tries once more with the compiled-in list alone, which every earlier build used (features/updater/src/engine.rs, call).

    • The union already contains that list, so this only matters if reading the store ever breaks the configuration; the update check can never fail where the build before it passed.
    • The archive stays pinned by the manifest's SHA-256 and checked by its signature.
  • New guardrail scripts/guardrails/net-trust.mjs: fails any of these outside crates/net-trust, the browser shim and a build script:

    • Agent::config_builder() and Agent::new_with_*;
    • ureq's default agent (ureq::get(...) and the like);
    • a hand-made RootCerts;
    • tungstenite::connect and client_tls, or client_tls_with_config without the shared configuration.

    On dev before this change it lists 25+ lines; on this branch, 0.

What does not change

  • Proxies: still taken from the environment variables only. The system proxy setting is a separate change.
  • Clock or captive portal: these refuse as before, since validity time and name are checked either way.
  • A server whose root is in no store: still refused.

Testing

Windows, this PR's build at fb7c95c36 against dev-488 (and repeated at 865803662 on the newer Rune pin: 49/49 public HTTPS accepted, 0/82 throwaway root accepted, 0.3 ms median verify, 6.1-9.8 ms store read for 73 roots), touching no certificate store or proxy setting. The app process alone was given a local proxy, which relays each connection and times the client's side of each handshake:

Check This PR dev-488
Public HTTPS (--server https://www.example.com, the release server) 98 of 98 accepted 73 of 73 accepted
Certificate from a throwaway root in no store 0 of 163 accepted 0 of 166 accepted
First certificate check, www.example.com 0.9 / 0.3 ms 0.5 / 4.8 ms
Median certificate check, all connections 0.3-0.4 ms 0.3-0.4 ms
Store read (73 roots), once per process 5.4-7.2 ms none

Linux, this PR's build at fb7c95c36 against dev-488, in a disposable VM whose own CA bundle (/etc/ssl/certs/ca-certificates.crt) took a throwaway root, against a local HTTPS server with a certificate from that root:

Phase This PR dev-488
A: root in no store (120 roots) refused (0 served) refused (0 served)
B: root appended to the bundle (121 roots) trusted: 25 requests served on 14 paths, content shown refused (0 served)
C: root removed again refused (0 served) -
  • Store read on Linux: 0.5-0.7 ms.
  • In B, one connection is dropped before the first request: the launch's plain TCP reachability check (Server::reachable), which dev-488 makes as well.
  • Local guardrails: 10/10 passed, web-clock.ts passed on head 4bc958289f.

Not run yet:

  • The update check on a signed build: a PR build is unsigned, so its updater stays off. It stays by reading (the same constructor, plus the fallback) until a signed check build of this branch is seen checking the real feed.
  • macOS: the store read (keychain and its trust settings) is by reading; its time is not measured yet.
  • Not exercised: a wss:// socket (by reading, it takes the same roots), SSL_CERT_FILE / SSL_CERT_DIR, other distributions' bundle paths, arm64.

Fixes #1290

Hona added 3 commits November 25, 2026 13:50
…he operating system does

The app's own requests (update check and download, server requests and event stream, pairing, plugin requests, web pictures, Hex, the office font) used ureq's default root list, the Mozilla roots compiled into the binary, and the MCP and terminal WebSockets used tungstenite's. Behind a network that inspects TLS with a company root in the system store, all of those failed as an unknown issuer, while the browser engine download (already on the platform verifier) and the official desktop app (Chromium) worked. A new crate, net-trust, gives every ureq agent the platform verifier and the WebSockets a rustls configuration with it; a guardrail fails any agent or socket built without it.
…efuses the update server

The update check is the one path a mistake cannot be fixed forward on: a build that cannot verify its feed can never fetch the build that repairs it. When the operating system's certificate check refuses the feed or the download (or the handshake fails), the updater tries once more with the Mozilla roots compiled into the app, the list every earlier build used, so it never fails where the build before it passed.
Hona added 2 commits November 25, 2026 15:20
… online revocation

Instead of the platform verifier, every HTTPS agent and wss socket verifies with webpki against the union of the Mozilla roots compiled into the app (webpki-root-certs) and the roots in the operating system's store (rustls-native-certs). It refuses nothing the compiled-in list accepts, trusts a company root installed in the store, and fetches no revocation online, so no first connection waits on a revocation server a network drops (the Windows verifier's 10 s accumulated timeout). The store is read once per process on the first https agent or socket: agents of a plain http:// base (the local server, Hex) read nothing, and the server's shared agent is made on its first request instead of in Server::new. The updater keeps its fallback to the compiled-in list.
@Hona Hona changed the title fix(net): every HTTPS request and wss socket checks certificates as the operating system does fix(net): every HTTPS request and wss socket trusts the system certificate store's roots Nov 25, 2026
@Hona
Hona marked this pull request as ready for review November 27, 2026 01:19
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.

Self-hosted HTTPS server with a local CA is shown as unreachable

1 participant