Repository navigation
fix(security): guard caller-controlled outbound URLs - #61
Open
zvonimirfras wants to merge 1 commit into
Open
zvonimirfras wants to merge 1 commit into
zvonimirfras wants to merge 1 commit into
Conversation
Agent api_endpoint and LLM config base_url are caller-controlled, and the services previously sent requests to any address they were given. That allowed SSRF to cloud metadata and internal hosts, and the /execute-test response returned the body to the caller. Add @ibm-vibe/outbound-guard, a Node-only package that: - refuses non-http(s) schemes and malformed URLs before any request - classifies IP literals (including IPv4-mapped, NAT64, 6to4, and alternate IPv4 spellings) and refuses always-blocked ranges - refuses private and loopback ranges per policy - resolves hostnames through a lookup guard that rejects any blocked address, closing DNS rebinding for the connected address - disables redirects and proxy handling for guarded requests Policy is set by OUTBOUND_ALLOW_LOOPBACK (default true) and OUTBOUND_ALLOW_PRIVATE_NETWORKS (default false). The agent service always refuses its own port and the backend port, so /execute-test cannot read back the backend's unauthenticated endpoints. Save-time: POST/PUT /api/llm-configs reject malformed base_url with 400 and warn on policy-blocked addresses. The call-time guard remains authoritative. Behaviour changes: outbound requests no longer follow redirects, and ignore HTTP_PROXY/HTTPS_PROXY. Stored rows written before this change are validated at call time only. Signed-off-by: Zvonimir Fras <zvonimir@zvonimirfras.com>
This branch has not been deployed
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
Agent
api_endpointand LLM configbase_urlare caller-controlled. The services previously sent requests to any address they were given, which allowed SSRF to cloud metadata and internal hosts./execute-testalso returned the response body to the caller.This PR adds
@ibm-vibe/outbound-guard, a Node-only package, and applies it to every caller-controlled outbound request.What changes
assertSafeOutboundUrl): refuses non-http(s) schemes and malformed URLs. Classifies IP literals, including IPv4-mapped IPv6, NAT64, 6to4, and alternate IPv4 spellings. Refuses always-blocked ranges, and private or loopback ranges per policy.guardedAxiosOptions): alookupthat rejects any hostname resolving to a blocked address, so the validated address is the one connected to. This closes DNS rebinding.makeApiRequestin agent-service-api; the Ollama, OpenAI, Anthropic, watsonx, and Bob calls in the backend. The watsonx guard runs before the IAM token request, so a blocked target never receives the API key. The fixed IAM URL is not guarded.POST/PUT /api/llm-configsreject malformedbase_urlwith 400, and warn (via awarningsarray) on policy-blocked addresses. DNS is never resolved at save time./execute-testfrom reading back the backend's unauthenticated endpoints.Configuration
OUTBOUND_ALLOW_LOOPBACKtrue127.0.0.0/8and::1, so local Ollama and local agents keep working.OUTBOUND_ALLOW_PRIVATE_NETWORKSfalseAlways blocked regardless of settings:
0.0.0.0/8, link-local169.254.0.0/16andfe80::/10, multicast, and the embedded-IPv4 transition ranges.Behaviour changes
/execute-testreturnsuccess: falsewith the messageOutbound request to this address is not allowed. The resolved address is never included.POST/PUT /api/llm-configsreturn 400 for a malformed or non-http(s)base_url.HTTP_PROXY/HTTPS_PROXY. Users behind a corporate proxy need to target the proxy directly for now.Known limitations
api_keyand headers. The guard limits where requests go, not what is sent.ECONNREFUSED,ENOTFOUND, and timeouts. Anonymising those is a separate decision.AgentFormModalmakes a browser-side request to a user-typed endpoint. It is out of scope for this PR.Testing
packages/outbound-guardhas 88 tests, with 94.9% branch coverage against a 90% threshold.makeApiRequest, the LLM service, and the save-time route checks. Existing exact-config assertions were updated to match the added guard options.169.254.169.254,[::ffff:a9fe:a9fe],2852039166, the agent service's own port, and the backend port were all refused without contacting the sink. WithOUTBOUND_ALLOW_LOOPBACK=false, the loopback target was refused.test:tsall pass.Signed-off-by: Zvonimir Fras zvonimir@zvonimirfras.com