Skip to content

fix(tools): check every webfetch redirect against the network policy - #529

Merged
mrnasil merged 1 commit into
mainfrom
fix/web-fetch-redirects
Dec 2, 2026
Merged

mrnasil merged 1 commit into
mainfrom
fix/web-fetch-redirects

Conversation

@mrnasil

@mrnasil mrnasil commented Dec 2, 2026

Copy link
Copy Markdown
Member

From the same source audit as #527 and #528.

Problem

webfetch checked security.network_allowlist / network_denylist against the first URL only. The HTTP client then followed redirects on its own, so an allowed host could send the fetch to any other host. The body was also read whole into memory before the result was cut to max_length, and a fetch had no overall timeout.

Change

  • The fetch client follows no redirect itself. get_checked follows them by hand: each hop is checked against the policy before it is requested, at most 10 hops. The result reports the final URL.
  • The body is read in chunks and cut at 5 MB.
  • A fetch (body included) times out after 60 s.

websearch keeps the shared client and its behaviour.

Not in this PR

A check of the resolved IP address (loopback, private, link-local) is still missing. It would also block local dev servers, so it needs its own setting.

Verification

  • New loopback tests: a relative redirect is followed and the final URL reported, a 304 is an answer and not a hop, a redirect to a blocked host is refused, a redirect loop stops at the limit, the body is cut at the byte limit.
  • Linux line coverage of crates/tools/src/web/fetch.rs measured locally with the web tests: no missed lines. The full whycodes-tools run could not finish locally because one GitHub API test fails in the offline measurement environment; CI measures the whole crate.

🤖 Generated with Claude Code

The allow and deny lists were applied to the first URL only; the client then
followed redirects on its own, so an allowed host could send the fetch
anywhere. Redirects are now followed by hand, each hop checked first, at most
ten. The body is read in chunks up to 5 MB instead of whole, and a fetch
times out after 60 s.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@mrnasil
mrnasil enabled auto-merge (squash) December 2, 2026 15:52
@mrnasil
mrnasil merged commit 068773e into main Dec 2, 2026
7 checks passed
@mrnasil
mrnasil deleted the fix/web-fetch-redirects branch December 2, 2026 15:58
@mrnasil mrnasil mentioned this pull request Dec 3, 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.

1 participant