Skip to content

Harden web_fetch SSRF and tool-renderer XSS guards - #1513

Open
daiv-agent[bot] wants to merge 1 commit into
mainfrom
fix/ssrf-and-xss-hardening
Open

Harden web_fetch SSRF and tool-renderer XSS guards#1513
daiv-agent[bot] wants to merge 1 commit into
mainfrom
fix/ssrf-and-xss-hardening

Conversation

@daiv-agent

@daiv-agent daiv-agent Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

This change hardens two security boundaries: the web_fetch middleware's SSRF protection now resolves DNS to catch rebinding and non-dotted IP encodings, and the chat tool-body renderer escapes quotes and gates non-http(s) URLs so attacker-controlled URLs cannot become script sinks in the DOM.

Key Changes:

  • Added _ip_is_blocked in daiv/automation/agent/middlewares/web_fetch.py, which unwraps v4-mapped/v4-compatible IPv6 addresses before checking private/loopback/link-local/reserved/multicast.
  • Added async _resolved_addresses_are_blocked, which resolves hostnames via asyncio.to_thread(socket.getaddrinfo) and blocks if any resolved address is internal — closing the DNS-rebinding gap and catching decimal/hex/octal IPv4 encodings the literal fast path treats as hostnames.
  • _fetch_url_text now checks both the string fast path and the resolver on every request (including redirects), and rejects cross-host redirects to non-http(s) schemes before the Location header is embedded in the <redirect_url> tag.
  • In daiv/chat/static/chat/js/tool-renderers.js, escapeHtml now also escapes double and single quotes, and externalLink renders only http:/https: URLs as anchors — javascript:/data: URLs become plain escaped text spans.
  • toolBodyHTML now routes its output through window.DOMPurify.sanitize (with FORBID_TAGS for style/form/input/button/iframe/object/embed) as the final security boundary before it feeds x-html.
  • Added tests/unit_tests/automation/agent/middlewares/test_web_fetch_ssrf.py cases (DNS-rebind to loopback/link-local/v4-mapped/unique-local, public pass-through, non-http(s) redirect blocking, same-host re-resolution) and new tests/unit_tests/chat/test_tool_renderers_xss.py + tool_renderers_driver.py that run the real tool-renderers.js under node.

⚠️ DAIV can make mistakes. Please review the changes and merge the MR if everything looks good.
🔗 Generated by DAIV — view sessions


💡 Instructions for the reviewer:

  • 💬 Just leave comments/reviews mentioning @daiv-agent to get DAIV to address them for you.

@daiv-agent daiv-agent Bot added the daiv Delegate issues to DAIV agent label Aug 19, 2026
@srtab srtab self-assigned this Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

daiv Delegate issues to DAIV agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant