Skip to content

fix(security): guard caller-controlled outbound URLs - #61

Open
zvonimirfras wants to merge 1 commit into
IBM:mainfrom
zvonimirfras:fix/outbound-url-guard
Open

zvonimirfras wants to merge 1 commit into
IBM:mainfrom
zvonimirfras:fix/outbound-url-guard

Conversation

@zvonimirfras

Copy link
Copy Markdown
Member

Summary

Agent api_endpoint and LLM config base_url are caller-controlled. The services previously sent requests to any address they were given, which allowed SSRF to cloud metadata and internal hosts. /execute-test also 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

  • Pre-flight check (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.
  • Connect-time guard (guardedAxiosOptions): a lookup that rejects any hostname resolving to a blocked address, so the validated address is the one connected to. This closes DNS rebinding.
  • Call sites: makeApiRequest in 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.
  • Save-time checks: POST/PUT /api/llm-configs reject malformed base_url with 400, and warn (via a warnings array) on policy-blocked addresses. DNS is never resolved at save time.
  • Denied ports: the agent service always refuses its own port and the backend port, even when loopback is allowed. This stops /execute-test from reading back the backend's unauthenticated endpoints.

Configuration

Variable Default Meaning
OUTBOUND_ALLOW_LOOPBACK true Allows 127.0.0.0/8 and ::1, so local Ollama and local agents keep working.
OUTBOUND_ALLOW_PRIVATE_NETWORKS false Allows RFC 1918, CGNAT, ULA, and documentation ranges.

Always blocked regardless of settings: 0.0.0.0/8, link-local 169.254.0.0/16 and fe80::/10, multicast, and the embedded-IPv4 transition ranges.

Behaviour changes

  1. Blocked targets make /execute-test return success: false with the message Outbound request to this address is not allowed. The resolved address is never included.
  2. Outbound requests no longer follow redirects. A 3xx is now an error.
  3. POST/PUT /api/llm-configs return 400 for a malformed or non-http(s) base_url.
  4. Outbound requests ignore HTTP_PROXY/HTTPS_PROXY. Users behind a corporate proxy need to target the proxy directly for now.
  5. Rows stored before this change are validated at call time only.

Known limitations

  • A public host that the caller controls can still receive the caller's api_key and headers. The guard limits where requests go, not what is sent.
  • Error messages for non-blocked failures still distinguish ECONNREFUSED, ENOTFOUND, and timeouts. Anonymising those is a separate decision.
  • The frontend's AgentFormModal makes a browser-side request to a user-typed endpoint. It is out of scope for this PR.

Testing

  • TDD: failing tests were written before each implementation.
  • Unit: packages/outbound-guard has 88 tests, with 94.9% branch coverage against a 90% threshold.
  • Service: guard tests for makeApiRequest, the LLM service, and the save-time route checks. Existing exact-config assertions were updated to match the added guard options.
  • Live: against a loopback sink, the allowed loopback target was reached. 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. With OUTBOUND_ALLOW_LOOPBACK=false, the loopback target was refused.
  • Gates: format, lint (0 errors), typecheck, and test:ts all pass.

Signed-off-by: Zvonimir Fras zvonimir@zvonimirfras.com

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant