Repository navigation
Description
Problem
Plugins, the registry discovery and gateways make outbound HTTP calls
whose targets may come from users or registries. Without guards they
are SSRF vectors (private addresses, redirects to internal hosts), can
hang past their deadline, or read unbounded responses. proTES has these
guards (check_public_host, is_public_address, fetch_json) in its
own code; FOCA should own them so all gateways and plugins share them.
Proposal
foca.utils.http, built on requests/urllib3 (no Werkzeug):
is_public_address(ip)(globally reachable, not multicast; embedded
IPv4 in IPv6 checked) andcheck_public_host(url)(resolve; all
addresses public; zone IDs refused), moved from proTES.GuardedClient(deadline=..., allow_private_addresses=False, max_response_size=...)withget/post/request: never follows
redirects, checks the host before each request, timeout = the remaining
deadline (connect timeout capped), streams responses up to the size
cap,httpsonly unless allowed; errors asfoca.utils.httpexception
classes (not-sent vs. maybe-sent distinguished, for gateway
classification).fetch_json(url, timeout, ...)for registry reads.- Engine:
ctx.httpis aGuardedClientbound to the hook's deadline. - Documented limitation: resolution-time check (DNS rebinding between
check and connect is mitigated by checking each request, not
eliminated).
Acceptance criteria
- Tests for public/private/special addresses (v4, v6, mapped, NAT64),
redirects refused, deadline honoured, size cap, unresolvable hosts;
no network access in tests (mocked resolver/adapters). - Docs: utilities page section; plugin author guide points to
ctx.http. - 100% coverage, mypy, ruff, semgrep (TLS verification never disabled),
mkdocs build --strict.
Surviving the Connexion 3 migration
Independent of the web framework (requests/urllib3 only). In 1.0 an
async variant (httpx) may be added for async hooks (P8); the sync
client stays.
Dependencies
- Blocked by feat(plugins): add plugin engine #486 for
ctx.httponly (stacked on feat(plugins): record provenance #488). - Blocks: feat(plugins): add typed backend lists #493 (P10).
Open questions
- None.
Added during pre-review: the deadline bounds the whole request (a watchdog shuts sockets down at the deadline; DNS resolution is bounded by the time left); each host is resolved once and the connection goes to a checked address (peer checked again); malformed URLs, ports, host labels and methods raise InvalidRequestURL; check_public_host(url, timeout=); HostNotResolved has reason dns_error; HttpResponse.url is removed; urllib3 is declared as a dependency; the engine closes each hook call's client.
Activity
test(http): cover deep JSON on all Pythons
fix(http): address Sourcery review
test(http): compare redacted messages exactly