Skip to content

Add the tool-rest runner (remote tools, executor step 3) - #4313

Merged
mstomar125 merged 2 commits into
mainfrom
issue-4291-rest-runner
Nov 19, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-4291-rest-runner

Conversation

@mstomar125

@mstomar125 mstomar125 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Refs #4291, executor step 3: the tool-rest runner. This PR changes packages/agent (and installs the runner in packages/daemon): the user's sign-off stands in for the agent owner's for this build. Everything from the tool-cli runner's reviews applies and is built in from the start.

What it adds

packages/agent/src/local_agent/rest_runner.rs (RestRunner), installed in the daemon's RemoteToolHost beside the tool-cli runner.

  • Binding and URL. ToolRestFields::from_bucket plus check_complete; malformed or incomplete fails closed. The method and headers come from the binding, never the model. The URL is built from the template with each {name} placeholder percent-encoded (everything but A-Za-z0-9-._~); a value of ., .. or empty is refused (a dot segment would climb out of the path); the result is parsed again and every use (scheme, host, port, request) comes from the parsed Url, never the stored text. Query parameters go through the URL's own serializer.
  • Model values only in declared slots: path placeholders, query parameters, and the json body (the arguments no other slot took, capped at 64 KiB). Never a header. With body: none, an argument with nowhere to go is refused.
  • https, except loopback. https always; http only for localhost or a loopback address; no user information; checked on every hop.
  • Addresses checked after resolution; connection pinned. Every address a name resolves to must be allowed: one private (10/8, 172.16/12, 192.168/16), link-local, unspecified, broadcast/multicast/reserved, shared (100.64/10), documentation or benchmarking address, or a v6 unique-local, link-local, site-local, multicast, documentation, IPv4-compatible or NAT64/IPv4-mapped form of any of those, refuses the call; loopback is allowed only when the binding's host is itself localhost or a loopback address (a name resolving to loopback is refused), and a destination named loopback must resolve only to loopback addresses (::ffff:127.x counts), so plain http to a loopback name can never reach a public address or carry a credential off the machine. Also blocked: 6to4 2002::/16, Teredo 2001::/32, 100::/64, 3fff::/20, 64:ff9b:1::/48, 5f00::/16, 192.0.0.0/24 and 192.88.99.0/24. The first checked address is the only one the client's resolver answers with (reqwest's dns_resolver), so the connection goes to the address that was checked with the original host kept for Host and TLS; the name is resolved once per hop (no rebinding window). A fake resolver in the tests returns a private address on the second call to show it is never used.
  • Redirects. Only within the same origin (scheme, host, port), at most three, each hop checked from the start; another origin (any other host, port or scheme, http included, a private address, user information) is never followed, so no credential or header reaches it. A redirect that would change a non-GET method is refused.
  • Credentials. The binding's auth reference is resolved only here and goes into one header of the requests to the binding's origin; zeroized; redacted from everything returned, for basic both the value and its base64 form. Over https, or over http only to a loopback host. A value with a control character or too short to redact is refused before any request.
  • No response header text in any message: a non-text content type is reported without repeating it (a server can put the credential in a header), and the HTTP client's own error text is redacted, stripped of control characters and cut.
  • No proxy, no cookies, no compression. HTTP_PROXY and friends are ignored on purpose (a credential is never silently routed through a proxy; tested with a proxy variable pointing at a listening server). No cookie store, no content decoding.
  • Limits. One total timeout (the credential store read, the name lookup, connect, every hop and the body: a server that drips a byte at a time and a resolver that never answers are both stopped); the confirmation's own lookup is bounded too (a timeout is a refused destination); the response is read as a stream and the connection is closed at the cap; a request body cap; Content-Length is not trusted.
  • The response is data. Text and JSON-like content types only (text/*, *json*, *xml*, form, javascript); no HTML rendering, nothing decoded as image or archive; no response header is returned (so a credential echoed in a header cannot reach the model); a non-2xx status is an error with a bounded, redacted piece of the body; with no content type, only valid UTF-8.
  • Redaction is the shared redactor. The byte-level sanitize (and cut) moved out of the tool-cli runner into local_agent/redaction.rs and both runners use it, with its exhaustive cut-position tests moved with it. The REST body is sanitized as raw bytes, with the partial-credential tail stripped when the read stopped at the cap.
  • Confirmation. Every call but a GET with no credential is confirmed (unchanged); a GET without auth is the only exemption and every SSRF and redirect rule still applies to it. The question is now built by the runner (RemoteToolRunner::confirmation_text, default = destination) so it can resolve first: it shows the method and origin, the resolved address(es), the credential reference (before anything long), then the path and query (cut with a marker), then the body (cut with a marker). If the destination is refused, the user is not asked and the call ends (host-authored refusal, not external).
  • Remote failure text is not shown to the user as the reason (unchanged); the external fence and system-prompt rule apply (unchanged).

Notes and limits

  • The system resolver runs on the blocking thread pool, so a lookup that never returns can hold one pool thread for as long as the OS lets it (the call itself is stopped by the timeout).

  • The credential-over-https check in run is redundant with the scheme rule (http only reaches a loopback host); it is kept as a second guard. The user-information check on a redirect target is unobservable (the origin comparison already refuses it); also kept.

  • Redaction is exact-value (and the base64 form for basic): a URL-encoded or JSON-escaped echo of a value containing ", \ or + is not caught. The confirm-to-run window is bounded by the check at run time. A model-controlled query argument can carry data to the bound origin, by design.

  • No production confirmer is wired yet, so as with tool-cli only a GET with no credential is offered; every other tool-rest call is not offered until the confirmation step lands.

  • The address shown in the question is the one resolved when it was built; run resolves again and checks again. A name that later points at a different public address is followed; a private one is refused.

  • Redaction replaces exact values: a transformed form of a credential in a body (other than the basic encoding) is not caught. The credential also sits in the HeaderValue the HTTP stack holds while the request is in flight.

  • A pure percent-encoding of a value is not a defence against a server that decodes twice; the model-chosen values are data for the bound origin.

  • The tests start loopback servers; nothing uses the real network. They set HTTP_PROXY-style variables in the test process (one test).

Tests

  • 31 rest_runner tests (27 first round, 4 in the review round: a loopback name resolving to a public address sends nothing, a credential in a Content-Type is not echoed, a hanging resolver is stopped by the total timeout and by the confirmation's own bound): placeholder encoding in the parsed URL, dot and empty values, query serializer, method/headers from the binding and the body from leftover arguments, an unmapped argument, a body cap, the three auth schemes with the credential redacted from a body and a response header that echo it, missing/short/CR-LF/control credentials stopping before any request, the address policy table (v4, v6, mapped, NAT64, documentation, shared, loopback by name vs localhost), a mixed answer refusing the call, names resolving to forbidden addresses, literal forbidden addresses, pinning with a rebinding resolver, the scheme and user-information rules, malformed bindings, same-origin redirects with method and body kept, cross-origin redirects (another port, name, scheme, a private address, protocol-relative, user information) never followed with the other server seeing nothing, the redirect limit and method-changing redirects, the streamed cap closing the connection, a dripping server and the total timeout, a cancelled call closing its connection, content types, non-2xx bodies bounded and redacted, the ignored proxy environment, and the confirmation text (resolved address, credential before a long path or body, a refused destination); one host test for a runner that refuses the destination. cargo clippy -D warnings clean; bun run test:changed passes.
  • 44 mutants: the first 31 caught, and in the review round 13 more caught (a loopback name allowed to resolve anywhere, mapped loopback, each added range: 6to4, Teredo, 100::/64, 3fff, 64:ff9b:1::/48, 5f00, 192.0.0.0/24, 192.88.99.0/24; the content type echoed; the confirmation lookup unbounded; the name lookup outside the total timeout). One survived and is untestable here: removing the redaction of the HTTP client's own error text (no way to make a real client error carry the credential); it is defence in depth. Earlier: (run in batches because of the 57-minute slot limit): placeholder values not encoded; dot segments and empty values allowed; an unmapped argument accepted; the request body uncapped; a cross-origin redirect followed; the redirect limit raised; a method-changing redirect followed; the proxy environment used; the connection not pinned; blocked addresses not refused; only the first address checked; private, link-local, mapped, unique-local and loopback-by-name addresses allowed; plain http allowed anywhere; user information allowed; the credential and its base64 form not redacted; binary content returned; the response buffered instead of stream-capped; static headers dropped; an error status returned as success; the error body uncapped; the confirmation missing the resolved address or the credential, or not cutting the body or path; the user asked when the destination is refused (found by the batch, covered by the new host test). Equivalent and not mutated: the client's own timeout and the outer total timeout each cover the same bound, so removing one alone changes nothing observable.

What remains

tool-mcp runner; the real confirmation wiring (bounded timeout, capped argument display); the enable-and-approve command (add-if-absent key write); the tool_whitelist decision; fixtures.

🤖 Generated with Claude Code

mstomar125 and others added 2 commits November 19, 2026 18:33
Sends the one request a tool-rest binding describes: URL built from the parsed
template with percent-encoded placeholders, https (http only to loopback),
addresses checked after DNS resolution and the connection pinned to the checked
address, same-origin redirects only, a credential only to the bound origin,
no proxy and no cookies, streamed and capped response returned as text data.
The redactor is shared with the tool-cli runner (new redaction module), and the
confirmation text now comes from the runner so it can show the resolved address.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…k, wider address blocklist, no response header text in errors, lookups under the timeouts

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
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