Skip to content
Merged
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
43 changes: 39 additions & 4 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,9 @@ tempfile = "3"
# `From<http::Response<T>>` impl needs the type. Already resolved to 1.5.0 as a
# transitive dependency of reqwest, so this pins nothing new and is test-only.
http = "1"
# The TLS server and the private certificate authority that prove a CA from
# `INCODE_CA_CERTS` is trusted (`runtime::http`). Generated at test time: no key
# is committed. Test-only; rustls and ring are already in Cargo.lock (as
# optional parts of reqwest's tree), rcgen is from the same project.
rcgen = "0.13"
rustls = { version = "0.23", default-features = false, features = ["ring", "std", "tls12"] }
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,27 @@ there gives way), and the memory
engine's files stay where they are. `INCODE_TRACE` (area `migrate`) says what
moved. The old `INCORD_*` variables are not read any more: rename them.

### Proxies and certificates

Behind a corporate proxy, every outbound request — the model API, web fetch and
search, MCP servers over HTTP and their OAuth, external tools and
`incode update`, the memory engine — follows `HTTPS_PROXY`, `HTTP_PROXY`,
`ALL_PROXY` and `NO_PROXY` (either case), and then the proxy set in Windows'
Internet Options or macOS' network settings. A request to **this machine** —
`localhost`, a `.localhost` name, `127.0.0.0/8` or `::1` — never goes through a
proxy, whatever `NO_PROXY` says, so a local memory engine, model server or MCP
server keeps working. Through a proxy, web fetch's check of where a name points
is made here, and the proxy resolves the name again itself: what the proxy can
reach is the proxy's to limit.

When the proxy re-signs TLS with the company's own certificate authority, point
`INCODE_CA_CERTS` (or `SSL_CERT_FILE`) at its PEM file — one or more
certificates. They are trusted beside the system's own. A file that cannot be
read, or holds no certificate, is said on stderr at the first request and
nothing extra is trusted, so a connection that needed it fails with a
certificate error rather than going elsewhere. A coding agent CLI incode drives
(claude, codex, agy) makes its own requests and reads its own settings.

## Security notes

- **No subscription login is read or held.** The agent CLIs authenticate
Expand Down
22 changes: 14 additions & 8 deletions src/agent/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1205,10 +1205,14 @@ impl Transport for Http {
.build()
.map_err(|e| format!("no runtime for the request: {e}"))?;
runtime.block_on(async move {
let client = reqwest::Client::builder()
.timeout(http.timeout)
.build()
.map_err(|e| format!("client: {e}"))?;
// A model server on this machine is reached directly, never
// through a proxy (`runtime::http`).
let client = crate::runtime::http::builder(crate::runtime::http::names_loopback(
&http.endpoint,
))
.timeout(http.timeout)
.build()
.map_err(|e| format!("client: {e}"))?;
let (response, retried) = http.post(&client, &payload).await?;
let status = response.status();
let text = response
Expand Down Expand Up @@ -1252,10 +1256,12 @@ impl Transport for Http {
.build()
.map_err(|e| format!("no runtime for the request: {e}"))?;
runtime.block_on(async move {
let client = reqwest::Client::builder()
.timeout(http.timeout)
.build()
.map_err(|e| format!("client: {e}"))?;
let client = crate::runtime::http::builder(crate::runtime::http::names_loopback(
&http.endpoint,
))
.timeout(http.timeout)
.build()
.map_err(|e| format!("client: {e}"))?;
let (mut response, retried) = http.post(&client, &payload).await?;
let status = response.status();
if !status.is_success() {
Expand Down
6 changes: 3 additions & 3 deletions src/brief.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1613,13 +1613,13 @@ fn fields_not_stored(update: &BriefUpdate, saved: &ProjectBrief) -> Vec<&'static
}
lost
}
use crate::runtime::http::{run_async, SHARED_CLIENT as HTTP_CLIENT};
use crate::runtime::http::{client_for, run_async};

/// Fetch a URL reusing the pooled HTTP client and ambient/shared runtime, returning body and optional ETag.
fn fetch_with_etag(url: &str) -> Result<(String, Option<String>), String> {
let url = url.to_string();
run_async(async move {
let response = HTTP_CLIENT
let response = client_for(&url)
.get(&url)
.timeout(FETCH_TIMEOUT)
.send()
Expand Down Expand Up @@ -1648,7 +1648,7 @@ fn post_with_etag(url: &str, body: String, etag: Option<&str>) -> Result<bool, S
let url = url.to_string();
let etag_owned = etag.map(str::to_string);
run_async(async move {
let mut req = HTTP_CLIENT
let mut req = client_for(&url)
.post(&url)
.timeout(FETCH_TIMEOUT)
.header("content-type", "application/json")
Expand Down
4 changes: 2 additions & 2 deletions src/ext_tools/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ pub(crate) fn get_bounded(

/// The response at the end of `url`'s redirects, each address checked first.
async fn follow(url: &str, accept: &str) -> Result<reqwest::Response, String> {
let client = crate::runtime::http::no_redirect_client()?;
let mut at = url.to_string();
for _ in 0..=MAX_REDIRECTS {
crate::agent::catalogue::key_may_travel_to(&at)
.map_err(|why| format!("refused to fetch it: {why}"))?;
let response = client
// Per hop: a redirect can lead off this machine, or onto it.
let response = crate::runtime::http::no_redirect_client(&at)?
.get(&at)
.header(reqwest::header::USER_AGENT, USER_AGENT)
.header(reqwest::header::ACCEPT, accept)
Expand Down
19 changes: 11 additions & 8 deletions src/mcp_oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,11 @@ pub(crate) struct Discovered {
pub(crate) scopes: Vec<String>,
}

/// A JSON document at `url`: `None` for an answer that is not a success.
async fn fetch_json(client: &reqwest::Client, url: &str) -> Result<Option<String>, String> {
let response = client
/// A JSON document at `url`: `None` for an answer that is not a success. The
/// client is chosen for `url` itself — metadata can live on another host than
/// the server, and only an address on this machine skips the proxy.
async fn fetch_json(url: &str) -> Result<Option<String>, String> {
let response = crate::runtime::http::no_redirect_client(url)?
.get(url)
.header(ACCEPT, "application/json")
.timeout(HTTP_BOUND)
Expand Down Expand Up @@ -495,7 +497,8 @@ async fn read_bounded(mut response: reqwest::Response) -> Result<String, String>
/// Find the authorization server for the MCP server at `server`.
async fn discover(server: String) -> Result<Discovered, String> {
checked(&server, "the server's address")?;
let client = crate::runtime::http::no_redirect_client()?;
// For the server only: each metadata document picks its own (`fetch_json`).
let client = crate::runtime::http::no_redirect_client(&server)?;
let hello = json!({"jsonrpc": "2.0", "id": 0, "method": "initialize",
"params": {"protocolVersion": crate::mcp_stdio::PROTOCOL_VERSION,
"capabilities": {},
Expand Down Expand Up @@ -530,7 +533,7 @@ async fn discover(server: String) -> Result<Discovered, String> {
candidates.extend(resource_metadata_candidates(&server)?);
let mut resource_metadata = None;
for candidate in &candidates {
if let Some(text) = fetch_json(client, candidate).await? {
if let Some(text) = fetch_json(candidate).await? {
resource_metadata = Some(parse_resource_metadata(&text, &server)?);
break;
}
Expand Down Expand Up @@ -561,7 +564,7 @@ async fn discover(server: String) -> Result<Discovered, String> {
}
};
for candidate in as_metadata_candidates(&issuer)? {
if let Some(text) = fetch_json(client, &candidate).await? {
if let Some(text) = fetch_json(&candidate).await? {
return Ok(Discovered {
server: parse_server_metadata(&text, &issuer)?,
resource,
Expand Down Expand Up @@ -884,7 +887,7 @@ struct Client {
/// Register incode as a public client (RFC 7591) for `redirect_uri`.
async fn register(endpoint: String, redirect_uri: String) -> Result<Client, String> {
checked(&endpoint, "its registration endpoint")?;
let client = crate::runtime::http::no_redirect_client()?;
let client = crate::runtime::http::no_redirect_client(&endpoint)?;
let request = json!({
"client_name": "incode",
"redirect_uris": [redirect_uri],
Expand Down Expand Up @@ -988,7 +991,7 @@ async fn token_request(
if let Some(resource) = &base.resource {
form.push(("resource", resource.clone()));
}
let client = crate::runtime::http::no_redirect_client()?;
let client = crate::runtime::http::no_redirect_client(&base.token_endpoint)?;
let response = client
.post(&base.token_endpoint)
.header(ACCEPT, "application/json")
Expand Down
2 changes: 1 addition & 1 deletion src/mcp_oauth_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ fn browse(address: &str) {
let address = address.to_string();
std::thread::spawn(move || {
let location = crate::runtime::http::run_async(async move {
let client = crate::runtime::http::no_redirect_client()?;
let client = crate::runtime::http::no_redirect_client(&address)?;
let answer = client
.get(&address)
.send()
Expand Down
Loading
Loading