Skip to content

fix(ai): web_fetch vetoes every redirect hop, reports failures as failures and renders pages as untrusted text #860

Closed

Description

@dan-petty

Context & Rationale

Filed from the unchecked P0 entry at docs/ROADMAP.md:878 (at 308a71f), which had no issue, so #739's migration would have dropped it (decision D9 of the 2026-10-01 agentic quality assessment).

This is a security defect: a public → link-local → public redirect chain reached the link-local hop (the entry's repro_wf.py). As a P0 security fix it qualifies as a critical fix for the current release if a person admits it; until then it is in the backlog. The entry splits the work into four PRs; only PR1 (the per-hop veto) is the P0, so this item is PR1, and PR2-PR4 are recorded below for refinement into their own items.

The Researcher harness (src/devops_cli/ai/harness/agents.py:130) calls fetch_web_page (src/devops_cli/ai/common_tools.py:360-387), which validates the URL once (:368), then follows redirects (:372); _validate_response_egress (:338-347) checks only the final resp.url, after all hops. The except Exception arm (:386-387) returns every failure, SSRF block included, as page text. resp.text (:378-380) skips the WHATWG BOM and <meta charset> steps. _html_to_markdown (:295-313) strips only <script>/<style>, escapes nothing and cuts at a raw offset (:384); _HTMLContentExtractor (src/devops_cli/ai/library/docs_ingester.py:39, :268) keeps dialogs, and _HEADING_PATTERN (:22) re-parses its unescaped text. PromptInjectionDefender's opt-in hook takes 3 arguments (src/devops_cli/ai/agents/guardrails.py:233); src/devops_cli/ai/agents/runner.py:72 passes 4 (TypeError, logged). The tool description (common_tools.py:394) and Core Vision principle 3 claim SSRF protection; tests/test_common_tools.py:109-125 sends no redirect and accepts any failure string. HttpClientBroker (src/devops_cli/http/broker.py:52-69) vetoes every hop in a request hook. vibes hit the same defects (docs/RETROSPECTIVE.md:163,164,169; examples/adaptive-web-crawler/markdown_extract.py:68-70).

Scope & Deliverables

  • Deliverable: PR1: route fetch_web_page through get_broker() (broker.py:170-172) so the hop walk, a max_redirects below httpx2's 20 (httpx2/_config.py:220) and the veto are the library's; _validate_request reads the tool's policy (validate_url_egress(allow_private=False), _validate_fetch_domain, common_tools.py:321-335) from request.extensions (broker.py:54-57,109-110). Add a 3xx-chain test (tests/test_http_broker.py). PR2: replace the except arm; raise ToolFailed (src/devops_cli/exceptions/ai.py:200) for non-2xx and connection failures (tool_failed, runner.py:156-158); let SSRFBlockedError reach error (:164-171). PR3: a default_encoding callable (httpx2/_models.py:539,672-680) prescans 1024 bytes for <meta charset>, then charset_normalizer, pinned in pyproject.toml; check resp.content for a BOM and set resp.encoding first. Port vibes test_crawler.py:306-351,396-475 onto httpx2.MockTransport. PR4: render_untrusted_page(html, url, budget) on markdownify>=1.2 MarkdownConverter(escape_misc=True, heading_style='ATX') and beautifulsoup4 as direct dependencies, not WebFetchLocalTool (escaping off, pydantic_ai/common_tools/web_fetch.py:121). Hand-roll only a convert_pre fence longer than any backtick run, a decompose() pass over chrome and [role=dialog], and a blank-line cut appending unused DEFAULT_TRUNCATION_SUFFIX (config/defaults.py:331). Return markdown, truncated, token_estimate, removed regions and a provenance line from the response URL, never <base>; wrap sanitize_prompt_boundary_tags output in <untrusted_web_page>; flag injection_suspected on a scan_text hit, without blocking. Delete _html_to_markdown and the fallback stub (common_tools.py:263-271). PR5: route ingest_remote_docs through it; delete _HTMLContentExtractor.
  • Acceptance criteria: each deliverable lands with a test that fails before it; tests never touch the network; uv run devops ci passes. Measured in the roadmap entry: .venv/bin/python -m pytest tests/test_common_tools.py tests/test_runtime_security_and_ssrf_hardening.py tests/test_http_broker.py -k 'web_fetch or broker': 13 passed. python repro_wf.py (web_fetch over httpx2.MockTransport): a public, link-local, public chain returned # Final after the transport received the link-local hop; an error status, a <meta charset> page and a BOM page came back as error text, mojibake and a kept BOM. python repro_broker2.py: the broker raised SSRFBlockedError before sending the second hop. python probe_html.py: _html_to_markdown emitted 3 of 3 chrome regions and an injected heading. mdvenv/bin/python md_probe2.py (markdownify escape_misc=True plus decompose()): 0 injected headings.
  • Key questions:
    • Is the Researcher harness used today? If nothing calls fetch_web_page, the fix still lands, because the MCP and agent tool surfaces expose it.
  • Constraint: PR1 ships the P0 alone. Veto each redirect request, not in a response hook. Keep the per-hop policy env-independent (DNS-rebinding test, tests/test_common_tools.py:128-133): validate_url (src/devops_cli/core/validation.py:186-243) admits private targets under DEVOPS_CLI_AI_ALLOW_PRIVATE_NETWORK (:219-225); validate_url_egress (:101-149) does not. build_headers (broker.py:46-50) injects traceparent (src/devops_cli/telemetry/context.py:86-92), so web_fetch builds its own headers. httpx2==2.13.0 is pinned (pyproject.toml:19); 302 tests never skip. Escape text nodes once, never inside code; a removed <main> must show in removed regions. SPA detection, headless escalation and strategy memory (vibes patterns/adaptive-headless-web-crawling.md:8) belong to v0.3.0.

Strategic Alignment

  • Milestone: Backlog (no release)
  • Depends on: none. Source: docs/ROADMAP.md:878 (308a71f).

Activity

  1. added
    type/security
    scope/ai
    priority/p0-critical
    on Oct 1, 2026
  2. added this to the v0.2.24 milestone on Oct 1, 2026
  3. dan-petty commented on Oct 1, 2026

    @dan-petty
    OwnerAuthor

    Admitted to v0.2.24 as a critical fix, by the owner's decision (2026-10-01): a P0 security defect fix, delivered before the cut.

  4. dan-petty commented on Oct 1, 2026

    @dan-petty
    OwnerAuthor

    Closed by #902, merged into release/v0.2.24.

    GitHub only acts on closing keywords when a pull request merges into the default branch, so this was closed by devops gh issues close-merged.

  5. added a commit that references this issue on Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p0-criticalscope/aitype/security

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions