Skip to content

feat(ai): web_fetch renders pages as untrusted, escaped markdown within a budget #896

Closed

Description

@dan-petty

Context & Rationale

#860 split the web_fetch hardening entry (docs/ROADMAP.md, at 308a71f line 878) into four PRs and delivered PR1, the per-hop egress veto, as a v0.2.24 critical fix. This is PR4. _html_to_markdown strips only script and style and escapes nothing, so a page can inject headings and instructions into what the model reads.

Scope & Deliverables

  • Deliverable: 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: every behaviour named above has a test that fails before the change; tests use httpx2.MockTransport and never touch the network; uv run devops ci passes.
  • Constraint: the per-hop veto from fix(ai): web_fetch vetoes every redirect hop, reports failures as failures and renders pages as untrusted text #860 stays the only egress check, and a failure is never returned as page text.

Strategic Alignment

Activity

  1. added
    type/security
    scope/ai
    priority/p1-high
    on Oct 1, 2026
  2. modified the milestones: , v0.2.28 on Oct 1, 2026
  3. dan-petty-bot commented on Oct 6, 2026

    @dan-petty-bot
    Collaborator

    What changed

    #1266, merged into release/v0.2.28 as 878fe3f.

    Context & Rationale

    Closes #896.
    Previously, _html_to_markdown stripped only script and style tags and escaped no special characters, enabling untrusted web pages to inject raw markdown headings, list items, or instructions into LLM context. Furthermore, chrome elements, dialog modals, and code fences containing backticks were not safely isolated.

    9 file(s) changed.

    How it was verified

    Check runs at a45572b:

    • Prune PR DevContainer Images: pass
    • CodeQL: pass
    • Static Analysis: pass
    • Analyze (actions): pass
    • Analyze (python): pass
    • Tests & Coverage: pass
    • DevContainer Image: skipping
    • Dependency Freshness: skipping
    • Service Image: skipping

    Acceptance Criteria of docs/agent/tasks/task-896-web-fetch-untrusted-escaped-markdown.md:

    No Acceptance Criteria section.

  4. added a commit that references this issue on Oct 7, 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/p1-highscope/aitype/security

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions