Skip to content

refactor(extension): route api-based extension requests through ssrf_proxy helper - #39521

Open
AlexMultiAgent wants to merge 2 commits into
langgenius:mainfrom
AlexMultiAgent:fix-api-extension-ssrf
Open

refactor(extension): route api-based extension requests through ssrf_proxy helper#39521
AlexMultiAgent wants to merge 2 commits into
langgenius:mainfrom
AlexMultiAgent:fix-api-extension-ssrf

Conversation

@AlexMultiAgent

@AlexMultiAgent AlexMultiAgent commented Jul 24, 2026

Copy link
Copy Markdown

Summary

  • api/core/extension/api_based_extension_requestor.py: remove the raw httpx.Client construction and the conditional SSRF_PROXY_HTTP_URL / SSRF_PROXY_HTTPS_URL mounts. Call core.helper.ssrf_proxy.make_request directly so the outbound request goes through Dify's standard URL/DNS validation and proxy enforcement.
  • api/tests/unit_tests/core/extension/test_api_based_extension_requestor.py: rewrite to mock core.extension.api_based_extension_requestor.make_request instead of httpx.Client. Add two new assertions that the requestor does not construct httpx.Client and does not read SSRF_PROXY_* config.

Fixes #39520.

Test Plan

  • uv run --project api pytest api/tests/unit_tests/core/extension/test_api_based_extension_requestor.py -q

@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jul 24, 2026
@AlexMultiAgent AlexMultiAgent changed the title fix(extension): route API-based extension requests through ssrf_proxy refactor(extension): route api-based extension requests through ssrf_proxy helper Jul 25, 2026
AlexMultiAgent and others added 2 commits July 25, 2026 10:14
`APIBasedExtensionRequestor.request` built a raw `httpx.Client` and
issued a POST to the user-supplied `api_endpoint`. SSRF protection
was conditional: only the optional `SSRF_PROXY_HTTP_URL` /`SSRF_PROXY_HTTPS_URL` mounts were applied, and when the proxy was not configured
the request went straight to the supplied URL — bypassing the
`core.helper.ssrf_proxy` checks every other internal client uses
to block loopback, link-local, and metadata destinations.

The api_endpoint is supplied by any logged-in tenant user at
`POST /console/api/api-based-extension` (and re-validated at save
time, plus re-invoked on every moderation input/output and
external_data_tool query). So an authenticated tenant could direct
the server to internal network addresses.

Replace the raw client + optional mounts with a single
`core.helper.ssrf_proxy.make_request` call, which performs the same
URL validation, DNS-resolution, and proxy enforcement as every
other Dify outbound call.
@AlexMultiAgent
AlexMultiAgent force-pushed the fix-api-extension-ssrf branch from cc21f64 to 3b59ae7 Compare July 25, 2026 02:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(extension): route API-based extension requests through ssrf_proxy

1 participant