Skip to content

net: loopback never through a proxy; trust INCODE_CA_CERTS (refs #26) - #41

Merged
blockmandev merged 2 commits into
mainfrom
feat/net-proxy-ca
Oct 22, 2026
Merged

blockmandev merged 2 commits into
mainfrom
feat/net-proxy-ca

Conversation

@blockmandev

Copy link
Copy Markdown
Member

#26 item 4: corporate proxy and custom CA.

What was already true

Every outbound client is reqwest 0.12 with its system-proxy default on, and none called .no_proxy().

  • That means HTTPS_PROXY, HTTP_PROXY, ALL_PROXY and NO_PROXY (either case) applied everywhere already. The Windows Internet Options or macOS proxy settings came next (hyper-util Matcher::from_system).
  • That covered the model API, web fetch and search, MCP over HTTP and OAuth, external tools and incode update, and the memory engine.
  • The no-redirect client was included.
  • This PR keeps that matcher. Replacing it with an explicit .proxy(..) would switch off the OS settings.

What was wrong

  • Loopback went through the proxy. reqwest's matcher sends loopback through the proxy too, unless NO_PROXY lists it (hyper-util-0.1.20 .../matcher.rs:122-133). With a corporate proxy set, the memory engine on 127.0.0.1, a local model server or a local MCP server was sent to a proxy that cannot reach them.
  • No company CA could be trusted. There was no way to trust the certificate authority a TLS-intercepting proxy re-signs with.

The change

runtime::http::builder(loopback) is now the base of every client.

  • This machine is never proxied. A client for this machine gets .no_proxy(). "This machine" means localhost, a .localhost name, 127.0.0.0/8 or ::1 (is_loopback).
    • The shared clients have direct twins, chosen per request: client_for(url), no_redirect_client(url), and request_text/request_empty, which build the request first and then pick by its URL.
    • The model API picks by its endpoint.
    • External-tool fetches pick per redirect hop.
  • Extra CA. INCODE_CA_CERTS, else SSL_CERT_FILE, names a PEM bundle that is trusted beside the system store (Certificate::from_pem_bundle).
    • A file that can't be read, or holds no certificate, is reported on stderr once and nothing is added. A connection that needed it then fails with a certificate error rather than quietly going elsewhere.
  • Direct clients follow a redirect only while it stays on this machine. One that led elsewhere would reach the other host with no proxy, past whatever the proxy enforces. This is the default for every builder(true) client; the no-redirect clients still follow none.
  • OAuth discovery picks a client per metadata URL (mcp_oauth::fetch_json), not the one chosen for the MCP server, because the metadata can live on another host.

Both of these came from a security review of the first commit.

  • Test a_redirect_from_this_machine_to_another_is_not_followed. Control: without the check, the direct client resolved the outside host itself.

  • Test the_client_is_chosen_by_the_address_it_is_for.

  • Web fetch keeps the system proxy. Through a proxy, the proxy resolves the name itself, so the IP pin cannot hold there; that was already the case. Its local checks still refuse a name that resolves inward. Both points are in the code comment and the README.

  • README: a new "Proxies and certificates" section.

Tests

Both network tests run a child process, so the proxy and CA environment is that process's alone. Each has a control.

  • a_loopback_request_skips_the_proxy_and_a_remote_one_takes_it. The child has HTTP_PROXY pointing at the sandbox crate's loopback proxy (deny-all, records every target) and no NO_PROXY.
    • A loopback service answers directly.
    • A .invalid name is asked of the proxy.
    • Control: without the loopback rule, the local request gets the proxy's 403.
  • a_server_signed_by_the_operators_ca_is_trusted_through_incode_ca_certs. A rustls server on localhost uses a certificate from a CA made at test time with rcgen.
    • Without INCODE_CA_CERTS the request is refused; with it, it is answered.
    • Control: without adding the roots, the trusted case fails ("root certificate which is not trusted", Windows schannel).
  • Unit tests:
    • this_machine_is_named_by_localhost_and_loopback_addresses_only
    • a_ca_bundle_is_read_from_the_environment_and_a_bad_one_is_said: precedence, a missing file, garbage, and a two-certificate bundle.

Local Windows gate: fmt, clippy -D warnings, cargo test (2209 lib + 59 bin).

Dependencies (dev-only)

  • rcgen 0.13 and rustls 0.23 (ring, no defaults) are used for the TLS test only.
  • rustls and ring were already in Cargo.lock as optional parts of reqwest's tree. New in the lock: rcgen, pem, yasna.
  • Cargo also re-unified four existing crates (errno, rustix, tempfile and one other) onto windows-sys 0.61.2, which was already in the tree in place of 0.59.
  • No key is committed.

Not covered

The coding-agent CLIs incode drives (claude, codex, agy) make their own requests with their own proxy and CA settings.

Every client is reqwest with its system proxy on, so HTTPS_PROXY,
HTTP_PROXY, NO_PROXY and the Windows/macOS proxy settings already
applied everywhere. But that matcher proxies loopback too unless
NO_PROXY names it, so the memory engine, a local model server or a
local MCP server went to a corporate proxy that cannot reach them, and
a proxy re-signing TLS with a company CA had no way to be trusted.
runtime::http::builder is now the base of every client: a client for
this machine gets no proxy (client_for, no_redirect_client(url), the
model API by its endpoint), and the PEM bundle INCODE_CA_CERTS (else
SSL_CERT_FILE) names is trusted beside the system store; one that
cannot be used is said and not added. Dev-only: rcgen and rustls
(ring) for an end-to-end TLS test against a CA made at test time.
…own client

Review of the previous commit: a client with no proxy followed any
redirect, so a local service redirecting elsewhere sent the request to
the other host past the proxy; and OAuth discovery reused the client
chosen for the MCP server for metadata URLs on other hosts. builder(true)
now follows a redirect only while it stays on this machine, and
mcp_oauth::fetch_json chooses the client for the URL it fetches.
@blockmandev
blockmandev merged commit 8e78987 into main Oct 22, 2026
15 of 17 checks passed
@blockmandev
blockmandev deleted the feat/net-proxy-ca branch November 15, 2026 20:29
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.

1 participant