refactor(extension): route api-based extension requests through ssrf_proxy helper - #39521
Open
AlexMultiAgent wants to merge 2 commits into
Open
refactor(extension): route api-based extension requests through ssrf_proxy helper#39521AlexMultiAgent wants to merge 2 commits into
AlexMultiAgent wants to merge 2 commits into
Conversation
`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
force-pushed
the
fix-api-extension-ssrf
branch
from
July 25, 2026 02:56
cc21f64 to
3b59ae7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
api/core/extension/api_based_extension_requestor.py: remove the rawhttpx.Clientconstruction and the conditionalSSRF_PROXY_HTTP_URL/SSRF_PROXY_HTTPS_URLmounts. Callcore.helper.ssrf_proxy.make_requestdirectly 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 mockcore.extension.api_based_extension_requestor.make_requestinstead ofhttpx.Client. Add two new assertions that the requestor does not constructhttpx.Clientand does not readSSRF_PROXY_*config.Fixes #39520.
Test Plan
uv run --project api pytest api/tests/unit_tests/core/extension/test_api_based_extension_requestor.py -q