fix(security): SSRF guard on Azure endpoint + validate Apify actor#163
Open
chakkiyar102 wants to merge 1 commit into
Open
fix(security): SSRF guard on Azure endpoint + validate Apify actor#163chakkiyar102 wants to merge 1 commit into
chakkiyar102 wants to merge 1 commit into
Conversation
…RF/path injection)
The settings router rebuilt the Azure OpenAI endpoint from user config and
fetched it to validate the key / list models, duplicating the LLM client's
URL construction but skipping its _validate_base_url SSRF guard. A configured
loopback / metadata / private endpoint could therefore be reached by the
probe and model-list paths, unlike the guarded discovery fetchers.
- api/routers/settings.py: reuse llm.client._validate_base_url on the Azure
endpoint in both probe_provider_key and list_provider_models, so the probe
reflects exactly what the client would accept (loopback/private -> raises
-> 'unreachable' / empty model list, no request made).
- discovery/sources/apify.py: allowlist the actor interpolated into the
acts/{actor}/... path so a configured actor cannot reshape the URL (path
traversal / host smuggling). Each <owner>/<name> segment must start and end
alphanumeric.
- Tests: tests/test_provider_endpoint_ssrf.py and
tests/test_apify_actor_validation.py cover both fixes without network.
All targeted unit tests + ruff pass.
|
Someone is attempting to deploy a commit to the Vasu-Devs' projects Team on Vercel. A member of the Team first needs to authorize it. |
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
Two small, surgical security hardening fixes found during a review of the discovery + LLM-provider surfaces. No behavior change for legitimate/public endpoints; only internal/loopback/malformed values are now refused at the same boundary the rest of the app already enforces.
1. SSRF guard on the Azure OpenAI endpoint (
api/routers/settings.py)llm/client.pyalready validates provider base URLs via_validate_base_url()(which reusescore.url_guard.is_public_host— loopback /169.254.169.254metadata / private LAN are refused). However,api/routers/settings.pyrebuilds the Azure endpoint independently inprobe_provider_keyandlist_provider_modelsand fetches it without that guard.A configured
azure_openai_endpointof e.g.http://127.0.0.1orhttp://169.254.169.254/...would therefore be probed, unlike every discovery fetch (which goes throughguarded_async_client).Fix: reuse the existing
llm.client._validate_base_urlso the probe reflects exactly what the real client would accept:_validate_base_urlraises →probe_provider_keyreturns"unreachable",list_provider_modelsreturns[]— no request made.2. Validate Apify actor (
discovery/sources/apify.py)run_actorinterpolatesactorstraight intohttps://api.apify.com/v2/acts/{actor}/.... The actor comes from user settings, so a malformed value could reshape the URL path. Added an allowlist: each<owner>/<name>segment must start and end alphanumeric (dots/dashes/underscores allowed inside), rejecting..,../x, empty, and whitespace.Tests
tests/test_provider_endpoint_ssrf.py— Azure loopback/metadata/private endpoints resolve to"unreachable"; missing endpoint stays"unchecked"(no network).tests/test_apify_actor_validation.py— regex accept/reject matrix +run_actorraisesValueErroron traversal/empty actor before any HTTP call.tests/test_url_guard.pystill passes.Out of scope (not changed here)
core/url_guard.py(check-time vs connect-time TOCTOU) — closing it fully needs IP-pinning at the httpcore transport layer; deliberately left as a larger follow-up rather than shipping an unvalidated transport rewrite here.tokenis still sent as a query param; header transport is a minor hygiene improvement left for a separate change to avoid any auth-compat risk.Type of change