Skip to content

fix(image-map): fetch search URLs through the SSRF-guarded session - #10264

Open
Laihu08 wants to merge 1 commit into
invoke-ai:mainfrom
Laihu08:fix/9633-ssrf-search-url
Open

Laihu08 wants to merge 1 commit into
invoke-ai:mainfrom
Laihu08:fix/9633-ssrf-search-url

Conversation

@Laihu08

@Laihu08 Laihu08 commented Nov 13, 2026 •

Copy link
Copy Markdown

Summary

_download_search_image fetched the reference-image URL with plain requests.get. That left two gaps in the allow-list: HTTP_PROXY/HTTPS_PROXY/ALL_PROXY made the request go through a proxy instead of the address that was checked, and 64:ff9b::/96 (NAT64) reports is_global == True, so 64:ff9b::7f00:1 mapped back to 127.0.0.1.

The fetch now uses build_guarded_session() (ignores ambient proxies, checks the connected peer) and _assert_url_host_allowed delegates to validate_download_url(), which blocks the NAT64 prefixes as reserved. The manual per-hop redirect loop and the 422 responses are unchanged.

Related Issues / Discussions

Closes #9633

QA Instructions

pytest tests/app/util/test_ssrf.py tests/app/routers/test_image_map.py
172 passed

The three new/updated tests in test_image_map.py (redirect re-validation through the guarded session, NAT64 literal and hostname rejected with 422 before any request, proxy env vars ignored) fail on main and pass with this change. ruff check and ruff format --check pass.

Review

Small change in one router; no API schema change.

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • Meaningful regression coverage added / updated where needed; obsolete tests/code removed
  • Persisted-state and API changes include required migrations / compatibility validation (none needed)
  • Relevant performance/efficiency opportunities considered; material claims have evidence
  • Material review findings resolved and relevant checks rerun
  • Documentation added / updated (if applicable)
  • Updated What's New copy (if doing a release after this PR)

AI assistance: this change was prepared with Claude (an AI coding assistant) and tested as described above.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

The reference-image URL fetch used plain requests.get, so HTTP(S)_PROXY and
ALL_PROXY bypassed the address check, and NAT64 addresses such as
64:ff9b::7f00:1 passed ipaddress.is_global. Use build_guarded_session() and
validate_download_url(), keeping the per-hop redirect validation and 422s.

Assisted-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added api python PRs that change python files python-tests PRs that change python tests labels Nov 13, 2026

This branch has not been deployed

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

Labels

api python PRs that change python files python-tests PRs that change python tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Semantic search URL fetch: allow-list is bypassed by HTTP proxy env vars, and by NAT64

1 participant