Skip to content

fix(retrieval): sanitize unexpected exception leakage in fetch url tool - #19616

Closed
naufalfx805-source wants to merge 1 commit into
BasedHardware:mainfrom
naufalfx805-source:fix/web-tools-exception-sanitization
Closed

naufalfx805-source wants to merge 1 commit into
BasedHardware:mainfrom
naufalfx805-source:fix/web-tools-exception-sanitization

Conversation

@naufalfx805-source

@naufalfx805-source naufalfx805-source commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Failure-Class: none

Problem

In backend/utils/retrieval/tools/web_tools.py, fetch_url_tool handles unexpected exceptions during page fetching by directly interpolating sanitize(str(e)) into the returned error message:

except Exception as e:
    logger.error(f"fetch_url_tool - error fetching {sanitize(url)}: {sanitize(str(e))}")
    return f'Error: Failed to fetch the URL. {sanitize(str(e))}'

While sanitize masks known PII patterns, raw exception strings from low-level network libraries (e.g., httpx, asyncio, ssl, DNS lookups, proxy transports) can expose internal network topology, proxy hostnames, connection pool errors, ports, or unexpected tracebacks directly into the agent tool response and model prompt.

Fixes #19617

Solution

  1. Mask Unexpected Exceptions: Update fetch_url_tool to return a safe generic message ('Error: Failed to fetch the URL. Please try again later.') while preserving full diagnostic details in logger.error.
  2. Preserve Validation Feedback: Legitimate input and SSRF validation errors (ValueError, unsupported scheme) remain unaffected.
  3. Hermetic Unit Tests: Added backend/tests/unit/test_fetch_url_tool_sanitization.py verifying that:
    • Unexpected exceptions during _fetch_page are sanitized and do not leak sensitive error messages/tokens.
    • Standard scheme and SSRF validation errors continue to be returned properly.

- Mask raw exception detail in fetch_url_tool with a safe generic error message
- Keep logger.error server-side logging for diagnostics while preventing infrastructure, network, and traceback disclosure to the model and user
- Add hermetic unit tests in test_fetch_url_tool_sanitization.py verifying error masking and preservation of validation errors
@naufalfx805-source
naufalfx805-source force-pushed the fix/web-tools-exception-sanitization branch from 4df34da to a22fd74 Compare September 28, 2026 17:54
@Git-on-my-level

Copy link
Copy Markdown
Member

Reviewed — this is a clean, well-scoped hardening of the fetch_url_tool error path, and it matches the acceptance intent of #19617.

backend/utils/retrieval/tools/web_tools.py — the change is exactly right: the broad except Exception branch now returns the static Error: Failed to fetch the URL. Please try again later. instead of interpolating sanitize(str(e)), so raw httpx/SSL/DNS/proxy exception strings (internal hostnames, ports, topology) no longer flow into the agent tool response and model prompt. Two things checked and confirmed good: (1) the except ValueError branch is untouched, so user-facing validation feedback (scheme check, URL resolves to a private or reserved address SSRF rejection) still surfaces; (2) logger.error(...) still records sanitize(str(e)) server-side, so diagnosability is preserved for operators.

backend/tests/unit/test_fetch_url_tool_sanitization.py — good hermetic coverage using the repo's load_module_fresh isolation harness: the leak-token test asserts the sensitive detail never reaches the tool output, and the second test pins both preserved validation messages (they match the current strings in web_tools.py). CI backend suite and hermetic merge gate pass.

Only minor observation, non-blocking: callers of the tool now get a less specific failure reason for transient network errors — that trade-off is the point of the fix and is fine.

Thanks for the contribution! Leaving the merge decision to a human maintainer. This feedback is AI-generated on behalf of the maintainer team.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added positive-signal Automation verified a genuine fix/quality contribution backend Backend Task (python) labels Sep 28, 2026
@aryanorastar

Copy link
Copy Markdown
Collaborator

Closing as a later copy of #19406. The earlier pull request is the one to keep.

@github-actions

Copy link
Copy Markdown
Contributor

Hey @naufalfx805-source 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing.

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend Task (python) positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bounty Proposal: Sanitize Unexpected Exception Leakage in Web Retrieval Tool

3 participants