Skip to content

web_fetch: opt-in default + save_to arg; allow curl in shell denylist - #144

Merged
FMXExpress merged 2 commits into
mainfrom
claude/webfetch-savefile-curl
Jun 5, 2026
Merged

FMXExpress merged 2 commits into
mainfrom
claude/webfetch-savefile-curl

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

Summary

Three related changes that restore parity with picoclaw's shell+curl posture while keeping web_fetch as a managed alternative for operators who want it.

1. Allow curl/wget in the shell denylist

Picoclaw's model fetches arbitrary URLs by shelling out to curl. Our denylist blocked both curl and wget , which put PasClaw strictly behind picoclaw on URL access. Removed both entries from Tools.Sandbox.ForbiddenSubstrings (array size updated 0..45 → 0..43). The rest of the denylist (sudo, rm -rf, dd, command-substitution, curl | sh-style pipes, package-manager installs, git push, etc.) is untouched. Operators who want the old posture can still flip the whole list off via sandbox.shell_deny_enabled = false.

2. web_fetch off by default

New Cfg.WebFetchEnabled: Boolean (default False, JSON-serialised only when True). Gates registration in all six callsites:

  • Cmd.Agent (via NewBuiltinRegistry's new EnableWebFetch parameter, same shape as EnableVault / EnableWebSearch)
  • Cmd.TUI, Cmd.Gateway, Cmd.Serve (inline if Cfg.WebFetchEnabled then …)
  • The two PasClaw.Agent.pas InstallTools paths (also inline)

Picoclaw doesn't ship a web_fetch — the model uses shell+curl — and the default posture now mirrors that. Operators on containerised / sandboxed deploys without curl can flip "web_fetch_enabled": true in config.json.

3. web_fetch grows save_to

Optional argument; when set, the full response body is written to that workspace-relative path (gated by Sandbox.CanWritePath) and the tool returns a short receipt + 200-char preview instead of the inlined content:

web_fetch: saved 1247892 bytes to workspace/scratch/page.html (status 200, content-type text/html; charset=utf-8)
preview: <!DOCTYPE html><html lang="en"><head>…

Skips the max_chars cap entirely so the model can pull arbitrary page sizes / JSON dumps / API dumps without blowing the context window, and skips the text/* content-type check so binary downloads work (image, PDF, etc.). The schema + description on the registered tool both call out the new convention so the model knows when to use it.

Test plan

  • FPC make clean && make clean, make smoke green.
  • pasclaw agent with default config (no web_fetch_enabled): tool absent from the registry, model uses shell+curl.
  • pasclaw agent with "web_fetch_enabled": true: tool registered.
    • web_fetch {url: "..."} returns inline text (existing behaviour).
    • web_fetch {url: "...", save_to: "workspace/test.html"} writes the file, returns the receipt + preview, file readable via fs_read.
    • web_fetch {url: ".../bigfile.json", save_to: "workspace/dump.json"} works for content types that used to error.
  • shell_exec with curl https://example.com no longer hits the denylist (returns curl's output).

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon


Generated by Claude Code

Three related changes that restore parity with picoclaw's
shell+curl posture while keeping web_fetch as a managed alternative
for operators who want it.

1. Drop 'curl ' and 'wget ' from the dangerous-shell denylist
   (Tools.Sandbox.ForbiddenSubstrings, array size 0..43). They were
   the model's conventional way to fetch arbitrary URLs and denying
   them put PasClaw strictly behind picoclaw on URL access. The full
   denylist remains toggleable via sandbox.shell_deny_enabled=false.

2. web_fetch is now off by default. New Cfg.WebFetchEnabled flag
   (off-by-default, serialised only when True) gates registration
   in all six callsites: Cmd.Agent (via NewBuiltinRegistry's new
   EnableWebFetch parameter), Cmd.TUI, Cmd.Gateway, Cmd.Serve, and
   the two PasClaw.Agent.pas InstallTools paths. Picoclaw doesn't
   ship a web_fetch — its model uses shell+curl — and the default
   posture now mirrors that.

3. web_fetch grows an optional `save_to` argument. When set, the
   full response body is written to that path under the workspace
   (gated by Sandbox.CanWritePath) and the tool returns a short
   receipt + 200-char preview rather than the inlined content.
   Skips the max_chars cap entirely so the model can pull arbitrary
   page sizes / JSON dumps without blowing the context window, and
   skips the text/* content-type check so binary downloads work.

The schema + description on the registered tool both call out the
new save_to convention so the model knows when to use it.

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2ab99495ae

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

a short receipt with a preview. }
if SaveTo <> '' then
begin
if not WriteBodyToFile(SaveTo, Resp.Body, ErrMsg) then Exit;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Serialize save_to fetches before dependent reads

When save_to is used, this branch mutates the workspace, but RegisterWebFetchTool still marks web_fetch as tcReadOnly. I checked PasClaw.Tools.ToolLoop.pas: consecutive read-only calls are batched and run in parallel, so a model turn that calls web_fetch {save_to:"page.html"} followed by fs_read/fs_grep of that file can race and have the read run before the download finishes. This write mode needs to be treated as mutating (or otherwise excluded from read-only batching) to preserve tool-call ordering for saved files.

Useful? React with 👍 / 👎.

Comment on lines +201 to +203
Bytes := TEncoding.UTF8.GetBytes(Body);
if Length(Bytes) > 0 then
FS.WriteBuffer(Bytes[0], Length(Bytes));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve raw bytes for saved downloads

For save_to, binary responses are first decoded into Resp.Body via TStringStream(..., TEncoding.UTF8) in the HTTP wrapper and then re-encoded here with TEncoding.UTF8.GetBytes, so non-text payloads such as PDFs, images, or zip files will not be saved byte-for-byte and may be corrupted. This matters because the new schema explicitly advertises save_to for binary downloads; it should use the existing stream-based HTTP path (or another byte-preserving path) instead of round-tripping through a string.

Useful? React with 👍 / 👎.

Two Codex P2 findings on the web_fetch save_to path:

1. Category mismatch. The tool was registered as tcReadOnly so the
   gateway scheduler would parallelise follow-up tool calls, but
   save_to writes to the workspace — a concurrent fs_read could
   observe a half-written file. Flip to tcMutating; the tool-level
   tag is the only signal the registry exposes (the inlined-text
   path doesn't mutate, but we can't tag per-call).

2. Binary content corruption. The save_to branch was fetching via
   GetURL (which returns a UTF-8 string body) then re-encoding to
   UTF-8 bytes via TEncoding.UTF8.GetBytes. For text the round trip
   is lossless, but for PDFs / images / archives the decode step
   replaces invalid byte sequences with U+FFFD and the file on disk
   ends up structurally broken — exactly the use case save_to was
   added to support.

Fix: add GetURLToStreamGuarded to the HTTP wrapper (both Indy and
NetHTTP backends) — same SSRF redirect guard + UA/Accept overrides
as GetURL, but writes raw response bytes into a caller stream
instead of decoding through TStringStream. WebFetch's save_to
branch now opens a TFileStream and streams bytes directly to disk;
the receipt preview is reconstructed by reading the first 200 bytes
back and only decoding when the Content-Type looks textual.

The non-save_to path is unchanged.
@FMXExpress
FMXExpress merged commit 99d499d into main Jun 5, 2026
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.

2 participants