Repository navigation
fix(web): self-hosted web tool endpoints can redirect requests to other hosts - #196847
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR restricts self-hosted web-tool requests and redirect hops to the configured endpoint hostname. Example: A configured endpoint at http://localhost:19390 redirects a search to http://ip6-localhost:19391/cross-final.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a current hostname-confinement gap with a focused change; no introduced correctness or security defect was found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherSearXNG, Brave and Firecrawl pass configured endpoint requests through a shared web-tool fetch helper, which supplies policy to the existing SSRF and redirect guard before network dispatch. flowchart TD
A[Configured web provider] --> B[Self hosted endpoint helper]
B --> C[Endpoint hostname policy]
C --> D[Guarded fetch redirect loop]
D --> E[Direct or proxy transport]
D --> F[Reject other hostname]
E --> G[Provider response]
Technical reviewBest possible solution: Keep hostname confinement in the existing self-hosted fetch owner while preserving configured private endpoints and same-host redirects. Do we have a high-confidence way to reproduce the issue? Current-main source shows the unrestricted private-network policy surviving redirect hops, and the supplied release/control traces demonstrate the resulting off-host request; no target code was executed during this review. Is this the best way to solve the issue? The patch is the smallest complete repair: derive the existing hostname policy at the shared self-hosted boundary and let the existing redirect guard enforce it for every consumer. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against fd8d012d70c7. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource -3, Tests +57, Other +3. Total +57 across 4 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (5 earlier review cycles)
Reviewed November 16, 2026, 7:36 PM ET / November 17, 2026, 00:36 UTC (Revision 6). |
Updated the description: added running-product evidence on base and head under Evidence, and removed the closing process note. @clawsweeper re-review |
|
@clawsweeper re-review
|
|
🦞👀 Re-review progress:
|
a2c15cc to
621237f
Compare
|
@clawsweeper re-review
|
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review
|
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review
|
|
🦞👀 Re-review progress:
|
…196847) (cherry picked from commit db3a484) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 1e0f5437b92e3323c3d4c9bfeeeb065d735911a3) (cherry picked from commit 75a18b930e9954881b7cf4c3e0df460dfc10f2b9)
…196847) Baseline adaptation: Use stable guarded fetch and its existing exact-host allowlist. Keep operator-configured private endpoints usable and verify the policy passed from the self-hosted endpoint owner. (cherry picked from commit db3a484) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit a7b18700b4883518f9d8318f91e2803a3943d334)
What Problem This Solves
Fixes: a self-hosted web tool endpoint (for example a private search instance) can redirect a request to a different host, and the request follows it with private-network access still enabled.
User Impact
User impact: requests to a self-hosted web tool endpoint now stay on the hostname that was configured, on every redirect hop. Configured private endpoints and same-host redirects keep working.
Required action for some deployments: if a self-hosted endpoint relies on redirecting to a different hostname, configure that destination hostname directly. Such redirects are now rejected.
Why This Change Was Made
Self-hosted endpoints need private-network access, but the shared self-hosted policy granted it without restricting the destination hostname. The policy is now derived from the configured endpoint URL using the existing URL hostname allowlist helper, together with the private-network grant. The allowlist is applied on each redirect hop, including environment-proxy dispatch. No new parser, guard or transport was added, and the helper's signature is unchanged for its consumers.
Evidence
Run with Node 24.22.2 and pnpm 12.15.0. No live endpoint, provider or proxy was contacted; DNS and transport are mocked.
src/agents/tools/web-guarded-fetch.redirects.test.ts) callswithSelfHostedWebToolsEndpointwith the real redirect and network guards. Onmainit fails 2 of 5 cases: in both direct and proxy mode, a same-host hop followed by a hop to another host returns that host's response. On this branch all 5 pass, including private DNS, IPv4 and IPv6 endpoint controls.main, 54 passed on this branch. Off-host requests stop before the second transport call; private-service and same-host controls succeed.Gap: the broad
pnpm checkreports 22 line-cap errors outside this change, which reproduce with identical diagnostics on an untouchedmain. Live provider and proxy integration were not exercised.Real network dispatch (loopback)
The exported
withSelfHostedWebToolsEndpointhelper was run from source with real DNS, real HTTP servers and the real transport. Nothing is mocked: no DNS or fetch replacement, no injected policy or dispatcher.b382a29a688a. Head:a2c15cc68999, this change before it was rebased onto currentmain; the patch is identical. Node 24.22.2.localhost. Server B is a different hostname,127.0.0.1, on another port. Both listen only on loopback inside a network namespace with no external interface./control(200),/same-host→/same-host-result(302 then 200), and the chain/search→/next→ B/result(two 302s). B logs every TCP connection and request.HTTP_PROXY/HTTPS_PROXYat a local forward proxy that supports CONNECT and logs what it forwards.GET /result; callback gets B's responseGET /result; callback gets B's responseHead rejection message in both modes:
Domain policy: Blocked hostname (not in allowlist): 127.0.0.1. Permitted hostname patterns: localhost.Limits: loopback fixtures over plain HTTP, not a real search provider or TLS endpoint; this exercises the shared helper boundary, not a full agent turn. The latest-stable upgrade run is below.
Upgrade trace: v2026.11.4 to this head
A real Gateway was started on each version against one persisted state directory, and
web_searchwas invoked three times throughPOST /tools/invokewith the real SearXNG provider. The search servers are loopback HTTP stand-ins; no model takes part. On both versions requests started only after/startupzreturned 200 withstatus: started.v2026.11.4(d843d6af39a4). Head:621237fdf4c6. Frozen-lockfile install and full build passed on both. Node 24.22.2.plugins.entries.searxng.config.webSearch.baseUrl = "http://localhost:19390". The config file was byte-identical from release shutdown through head Doctor and head Gateway (SHA-25617f338d5eed03df4f52eb58948fd83550c4795e0ce6cad276e2b60c1e392206d). No manual state edit and no downgrade override.localhost:19390. Server B is a different hostname,ip6-localhost:19391.Provider requests in arrival order, all
GET:/search?q=ordinary&format=json/search?q=same&format=json/same-final/search?q=cross&format=json/cross-finalOrdinary and same-host searches return results on both versions. The release follows the cross-host redirect and B receives 1 request. Head rejects
ip6-localhostunder the hostname policy, B receives 0 requests, and the tool returns a SearXNGprovider_errorpayload.Limits: this shows request behavior after a release-to-head state handoff, not a clean upgrade.
openclaw doctorexited 0 on the release and 1 on head: head refused thesession-entry-statemigration before Gateway start and reported two shared-state inspection failures afterwards. Head's Gateway migrated state/agent schemas from 22/27 to 40/42 using its built-in generic-copy fallback (previous databases retained, conservation reported OK). This change touches onlysrc/agents/tools/web-guarded-fetch.tsand its tests;mainwithout it was not run as a control. The fixture is isolated, with no model configured and a restricted temporary directory, which produced the same warnings on both versions. Plain HTTP stand-in servers; no HTTPS. The agent-turn run is below. The same trace run fromv2026.11.3gave the same request results.Agent turn through the Gateway: v2026.11.4 and this head
The same three searches, driven by full agent turns rather than direct tool calls. Each turn was sent with the documented
openclaw agent --agent main --message … --jsonthrough the running Gateway, after/startupzreturned 200. The agent loop made two model requests per turn: the model asked forweb_search, the product ran the real SearXNG provider, and the model received the tool result and replied. The model is a deterministic loopback stand-in speaking the native Ollama protocol, not a hosted model; every model request body was captured. Same builds, setting and servers A and B as the upgrade trace, on a fresh state directory provisioned by the release./search200/search200/search302, A/same-final200/search302, A/same-final200/search302, B/cross-final200/search302, no request to Bprovider_errorAll six turns completed with CLI exit 0 and a final reply. B received 1 request across the release turns and 0 across the head turns. On head the Gateway logged
Blocked hostname (not in allowlist): ip6-localhost, and the model's reply reported the error instead of B's content.Limits: model and search servers are loopback stand-ins; no hosted model, external search engine or HTTPS. The Doctor and state-migration observations from the upgrade trace apply unchanged to this run.