Skip to content
pi-c Artifact [8614c6418f]
Login

Artifact [8614c6418f]

Artifact 8614c6418fe1f9b458c3c8d2bed3dbf29b03be90869c39090c10bc7f799584c2:


# web_fetch

Status: built 2026-11-27 (ticket 90, first half; search follows). Tier: bundled (`src/webfetch.c`,
`src/htmltext.c`), over the transport's web mode in core (`src/net.c`). Clock: taste. Record: none
new; a call is an effect, replay-safe. Default: on.

The tool is a registration (`pic_webfetch_tool`, [the tool registry](../design/keel.md)): a GET of
one URL through `pic_http_get`, redirects followed by the tool, not the transport, so every hop is
parsed, checked and counted by one function.

## The address check

A model chooses the URL, so the fetch must not reach the user's machine or network. The check is
`pic_net_web` in `net.c`, made on each address `pic_net_connect` is about to connect to, after the
name lookup. Checking the connected address, and not the URL's host, is what defeats a name that
resolves to a private address, a name whose answer changes between a check and the connect, and a
redirect: each hop is a new connection with its own check. Refused: IPv4 0/8, 10/8, 100.64/10,
127/8, 169.254/16 (metadata included), 172.16/12, 192.0.0/24, 192.0.2/24, 192.88.99/24,
192.168/16, 198.18/15, 198.51.100/24, 203.0.113/24 and 224/3; IPv6 outside 2000::/3 (so fc00::/7,
fe80::/10, ff00::/8, ::1 and ::), Teredo, 2001:db8::/32; and the IPv6 forms that carry an IPv4
address (::ffff:a.b.c.d, 64:ff9b::/96, 2002::/16) by that address. `wf_parse` also writes an IPv4
host given as a number, in octal or hex, or short (`127.1`) as its dotted quad, so every resolver
reads it alike. A URL with a user name or password is refused.

Web mode also lets plain `http://` go to any host, which the transport otherwise allows to loopback
only. It is off unless the tool turns it on for its own connection.

Test seams (dev builds only, never in a release build): `PIC_TEST_WEB_LOOPBACK=PORT` lets the one
loopback port of the fake server through the check; `PIC_TEST_WEB_DEADLINE=SECONDS` shortens the
30 second deadline. `test/pic/webfetch.sh --no-faults` checks that a release build refuses
loopback.

## Limits

Five redirects (the sixth fails), 5 MB of body (refused on a Content-Length over it, and when a
body without one grows past it), 30 seconds for the whole call across all hops, text types only
(`text/*`, JSON, XML, JavaScript, YAML, and a body with no type that has no NUL byte). The result
is cut to `max_chars`; the whole converted text goes to `pic_tool_hooks.output`, kept as
`pic:output/N` for `read`.