@devries-cameron20 / composio-1 / commits / eccb80ef1
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

fix(cli): block SSRF in proxy binary downloads (#4511)

This PR: - closes [SEC-1179](https://linear.app/composio/issue/SEC-1179/composio-attacker-can-reach-internal-services-using-ssrf-to-steal) - routes proxy binary downloads through the core `ssrfSafeFetch` guard - requires validation-to-connection pinning and fails closed when a configured dispatcher or proxy prevents it - reapplies that requirement on every redirect hop while preserving default SDK proxy compatibility - covers direct metadata targets, configured-route bypasses, redirects, and the bundled Bun companion - verifies the full core and CLI suites plus the TypeScript workspace typecheck

Alberto Schiabel committed Sep 17, 2026 at 15:20 UTC eccb80ef10d6ed32b71abb93a1f8be3dbd5c6686
7 files changed +239 -8
.changeset/tidy-keys-protect.md new
+6
@@ -0,0 +1,6 @@
1 +---
2 +'@composio/core': patch
3 +---
4 +
5 +Add an opt-in strict mode to `ssrfSafeFetch` that rejects configured network
6 +routes when the connection cannot be pinned to the validated address.
ts/packages/cli/CHANGELOG.md
+4
@@ -4,6 +4,10 @@
4
5 ### Patch Changes
6
7 +- `composio run` now validates binary download URLs returned by the proxy API
8 + before fetching them. Private, loopback, link-local, and redirect-based SSRF
9 + targets are blocked, DNS resolutions are pinned to prevent rebinding, and the
10 + download fails closed when a configured proxy prevents address pinning.
11 - The plugin hint shown under Claude Code or Codex now reads
12 `'composio setup --yes' installs it`, and setup error messages that suggest
13 a rerun now include `--yes` too, so an agent following the printed text no
ts/packages/cli/src/services/run-helpers-runtime.ts
+8 -1
@@ -2,6 +2,7 @@
2 // runtime or @effect/platform layers are provided, so it uses sync Node builtins.
3 // eslint-disable-next-line no-restricted-imports -- sync fs for run-log appends, run-file writes, and CLI config reads in the child process, outside the Effect runtime
4 import * as fs from 'node:fs';
5 +import { ssrfSafeFetch } from '@composio/core/utils/ssrf-guard';
6 import { ChildProcess as Command } from 'effect/unstable/process';
7 import * as Path from 'effect/Path';
8 import * as BunServices from '@effect/platform-bun/BunServices';
@@ -444,7 +445,13 @@ const normalizeFetchInput = async (input: unknown, init: RequestInit = {}) => {
445 const toProxyResponse = async (result: ProxyExecuteResponse) => {
446 const headers = new Headers(result?.headers || {});
447 if (result?.binary_data?.url) {
447 - const binaryResponse = await fetch(result.binary_data.url);
448 + const binaryResponse = await ssrfSafeFetch(
449 + result.binary_data.url,
450 + {},
451 + {
452 + requirePinnedConnection: true,
453 + }
454 + );
455 binaryResponse.headers.forEach((value, key) => {
456 if (!headers.has(key)) headers.set(key, value);
457 });
ts/packages/cli/test/src/services/run-helpers-runtime.test.ts
+107
@@ -62,6 +62,113 @@ describe('run-helpers-runtime', () => {
62 expect(fetchMock).toHaveBeenCalledOnce();
63 });
64
65 + it('[Given] a proxy binary URL targets cloud metadata [Then] it blocks the download', async () => {
66 + const fetchMock = vi
67 + .fn()
68 + .mockResolvedValueOnce(
69 + new Response(JSON.stringify({ session_id: 'session-1' }), {
70 + status: 200,
71 + headers: { 'content-type': 'application/json' },
72 + })
73 + )
74 + .mockResolvedValueOnce(
75 + new Response(
76 + JSON.stringify({
77 + binary_data: {
78 + url: 'http://169.254.169.254/latest/meta-data/iam/security-credentials/',
79 + },
80 + status: 200,
81 + }),
82 + {
83 + status: 200,
84 + headers: { 'content-type': 'application/json' },
85 + }
86 + )
87 + )
88 + .mockResolvedValueOnce(new Response('stolen cloud credentials', { status: 200 }));
89 + vi.stubGlobal('fetch', fetchMock);
90 +
91 + await installRunHelpers({
92 + cliPrefix: ['composio'],
93 + helperContext: {
94 + apiKey: 'test-key',
95 + orgId: 'test-org',
96 + consumerProjectId: 'test-project',
97 + consumerUserId: 'test-user',
98 + },
99 + });
100 +
101 + const installedGlobals: unknown = globalThis;
102 + expect(Predicate.hasProperty(installedGlobals, 'proxy')).toBe(true);
103 + if (
104 + !Predicate.hasProperty(installedGlobals, 'proxy') ||
105 + typeof installedGlobals.proxy !== 'function'
106 + ) {
107 + throw new Error('installRunHelpers() did not install proxy().');
108 + }
109 +
110 + const proxyFetch = await installedGlobals.proxy('github');
111 + await expect(proxyFetch('https://api.github.com/user')).rejects.toMatchObject({
112 + code: 'TS-SDK::BLOCKED_INTERNAL_URL',
113 + name: 'ComposioBlockedInternalUrlError',
114 + });
115 + expect(fetchMock).toHaveBeenCalledTimes(2);
116 + });
117 +
118 + it('[Given] a configured proxy prevents pinning [Then] it blocks the binary download', async () => {
119 + vi.stubEnv('NODE_USE_ENV_PROXY', '1');
120 + vi.stubEnv('HTTPS_PROXY', 'http://proxy.example:3128');
121 + vi.stubEnv('NO_PROXY', '');
122 + const fetchMock = vi
123 + .fn()
124 + .mockResolvedValueOnce(
125 + new Response(JSON.stringify({ session_id: 'session-1' }), {
126 + status: 200,
127 + headers: { 'content-type': 'application/json' },
128 + })
129 + )
130 + .mockResolvedValueOnce(
131 + new Response(
132 + JSON.stringify({
133 + binary_data: { url: 'https://1.1.1.1/proxy-response.bin' },
134 + status: 200,
135 + }),
136 + {
137 + status: 200,
138 + headers: { 'content-type': 'application/json' },
139 + }
140 + )
141 + )
142 + .mockResolvedValueOnce(new Response('untrusted proxied response', { status: 200 }));
143 + vi.stubGlobal('fetch', fetchMock);
144 +
145 + await installRunHelpers({
146 + cliPrefix: ['composio'],
147 + helperContext: {
148 + apiKey: 'test-key',
149 + orgId: 'test-org',
150 + consumerProjectId: 'test-project',
151 + consumerUserId: 'test-user',
152 + },
153 + });
154 +
155 + const installedGlobals: unknown = globalThis;
156 + expect(Predicate.hasProperty(installedGlobals, 'proxy')).toBe(true);
157 + if (
158 + !Predicate.hasProperty(installedGlobals, 'proxy') ||
159 + typeof installedGlobals.proxy !== 'function'
160 + ) {
161 + throw new Error('installRunHelpers() did not install proxy().');
162 + }
163 +
164 + const proxyFetch = await installedGlobals.proxy('github');
165 + await expect(proxyFetch('https://api.github.com/user')).rejects.toMatchObject({
166 + code: 'TS-SDK::BLOCKED_INTERNAL_URL',
167 + name: 'ComposioBlockedInternalUrlError',
168 + });
169 + expect(fetchMock).toHaveBeenCalledTimes(2);
170 + });
171 +
172 it('[Given] normalized false flags [Then] nested CLI children receive false explicitly', async () => {
173 vi.stubEnv('COMPOSIO_RUN_ENV_SENTINEL', 'forwarded');
174 vi.stubEnv('COMPOSIO_PERF_DEBUG', '1');
ts/packages/core/src/utils/ssrfGuard.node.ts
+29 -6
@@ -27,7 +27,7 @@ import {
27 * to a public address during validation and rebind to an internal one before
28 * the connect — a TOCTOU window the Python guard closes the same way.
29 *
30 - * Residual: a hop whose effective dispatcher is a configured route — a
30 + * By default, a hop whose effective dispatcher is a configured route — a
31 * caller-supplied `init.dispatcher`, a non-stock global dispatcher (a
32 * `ProxyAgent` or `EnvHttpProxyAgent` installed via `setGlobalDispatcher`), or
33 * the runtime's env-proxy mode (automatic on Bun, opt-in via
@@ -35,11 +35,22 @@ import {
35 * pre-flight validation. Pinning would dial the validated address instead of
36 * the proxy, and the proxy resolves the hostname itself where the SDK cannot
37 * see or pin that resolution. The Python guard carries the same residual for
38 - * the same reason (`_proxy_applies`).
38 + * the same reason (`_proxy_applies`). Callers that cannot accept that residual
39 + * can set `requirePinnedConnection`, which fails closed before fetching.
40 */
41
42 const MAX_REDIRECTS = 5;
43
44 +export interface SsrfSafeFetchOptions {
45 + /** Maximum number of redirects to follow. Defaults to 5. */
46 + maxRedirects?: number;
47 + /**
48 + * Refuse a request when a configured dispatcher or environment proxy means
49 + * the connection cannot be pinned to the address validated by the guard.
50 + */
51 + requirePinnedConnection?: boolean;
52 +}
53 +
54 /**
55 * The Fetch standard's "redirect status" set. A 3xx outside it is not a
56 * redirect to follow even when it carries a `location` — `304 Not Modified`
@@ -305,15 +316,20 @@ export const assertSafeFetchTarget = async (rawUrl: string): Promise<string[]> =
316 * returned unchanged. Each hop carries the method, body, and credential headers
317 * the Fetch standard says it should — see {@link applyRedirectSemantics}.
318 *
308 - * A hop whose effective dispatcher is a configured route (caller-supplied
309 - * `init.dispatcher`, non-stock global dispatcher, env-proxy mode) is *not*
310 - * pinned — see the module residual above.
319 + * By default, a hop whose effective dispatcher is a configured route
320 + * (caller-supplied `init.dispatcher`, non-stock global dispatcher, env-proxy
321 + * mode) is *not* pinned. Set `requirePinnedConnection` to fail closed instead.
322 */
323 export const ssrfSafeFetch = async (
324 rawUrl: string,
325 init: RequestInit = {},
315 - maxRedirects: number = MAX_REDIRECTS
326 + optionsOrMaxRedirects: SsrfSafeFetchOptions | number = {}
327 ): Promise<Response> => {
328 + const options =
329 + typeof optionsOrMaxRedirects === 'number'
330 + ? { maxRedirects: optionsOrMaxRedirects }
331 + : optionsOrMaxRedirects;
332 + const maxRedirects = options.maxRedirects ?? MAX_REDIRECTS;
333 let currentUrl = rawUrl;
334 // Rebound per hop: a redirect can drop the method and body (see
335 // `applyRedirectSemantics`), and the following hops must send what is left.
@@ -332,6 +348,13 @@ export const ssrfSafeFetch = async (
348 envProxyApplies(new URL(currentUrl), isBun) ||
349 hasCustomGlobalDispatcher();
350
351 + if (options.requirePinnedConnection && respectConfiguredRoute) {
352 + throw new ComposioBlockedInternalUrlError(
353 + 'Refusing to fetch through a configured network route because the validated address cannot be pinned',
354 + { url: currentUrl }
355 + );
356 + }
357 +
358 const dispatcher =
359 respectConfiguredRoute || isBun ? undefined : await createPinnedDispatcher(addresses);
360
ts/packages/core/src/utils/ssrfGuard.workerd.ts
+11 -1
@@ -1,5 +1,15 @@
1 import { ComposioBlockedInternalUrlError } from '../errors/SsrfErrors';
2
3 +export interface SsrfSafeFetchOptions {
4 + /** Maximum number of redirects to follow. Defaults to 5. */
5 + maxRedirects?: number;
6 + /**
7 + * Refuse a request when a configured dispatcher or environment proxy means
8 + * the connection cannot be pinned to the address validated by the guard.
9 + */
10 + requirePinnedConnection?: boolean;
11 +}
12 +
13 /**
14 * Edge runtimes do not expose the DNS resolution APIs needed to prove that a
15 * hostname is publicly routable before connecting. Fail closed instead of
@@ -8,7 +18,7 @@ import { ComposioBlockedInternalUrlError } from '../errors/SsrfErrors';
18 export const ssrfSafeFetch = async (
19 rawUrl: string,
20 _init: RequestInit = {},
11 - _maxRedirects?: number
21 + _optionsOrMaxRedirects: SsrfSafeFetchOptions | number = {}
22 ): Promise<Response> => {
23 throw new ComposioBlockedInternalUrlError(
24 'URL file uploads are not supported in edge runtimes because the destination cannot be safely validated',
ts/packages/core/test/utils/ssrfGuard.test.ts
+74
@@ -292,6 +292,80 @@ describe('ssrfSafeFetch', () => {
292 );
293 });
294
295 + it('fails closed in strict mode when a caller dispatcher prevents pinning', async () => {
296 + resolvesTo('93.184.216.34');
297 +
298 + await expect(
299 + ssrfSafeFetch('https://example.com/file.pdf', { dispatcher: {} } as RequestInit, {
300 + requirePinnedConnection: true,
301 + })
302 + ).rejects.toBeInstanceOf(ComposioBlockedInternalUrlError);
303 +
304 + expect(mockCreatePinnedDispatcher).not.toHaveBeenCalled();
305 + expect(mockFetch).not.toHaveBeenCalled();
306 + });
307 +
308 + it('fails closed in strict mode when a custom global dispatcher prevents pinning', async () => {
309 + resolvesTo('93.184.216.34');
310 + mockHasCustomGlobalDispatcher.mockReturnValue(true);
311 +
312 + await expect(
313 + ssrfSafeFetch('https://example.com/file.pdf', {}, { requirePinnedConnection: true })
314 + ).rejects.toBeInstanceOf(ComposioBlockedInternalUrlError);
315 +
316 + expect(mockCreatePinnedDispatcher).not.toHaveBeenCalled();
317 + expect(mockFetch).not.toHaveBeenCalled();
318 + });
319 +
320 + it('fails closed in strict mode when Bun would use an environment proxy', async () => {
321 + resolvesTo('93.184.216.34');
322 + vi.stubEnv('HTTPS_PROXY', 'http://proxy.example:3128');
323 + vi.stubEnv('NO_PROXY', '');
324 + const bunDescriptor = Object.getOwnPropertyDescriptor(process.versions, 'bun');
325 + Object.defineProperty(process.versions, 'bun', {
326 + configurable: true,
327 + value: '1.4.0',
328 + });
329 +
330 + try {
331 + await expect(
332 + ssrfSafeFetch('https://example.com/file.pdf', {}, { requirePinnedConnection: true })
333 + ).rejects.toBeInstanceOf(ComposioBlockedInternalUrlError);
334 + } finally {
335 + if (bunDescriptor) {
336 + Object.defineProperty(process.versions, 'bun', bunDescriptor);
337 + } else {
338 + delete (process.versions as NodeJS.ProcessVersions & { bun?: string }).bun;
339 + }
340 + }
341 +
342 + expect(mockPinnedHttpFetch).not.toHaveBeenCalled();
343 + expect(mockFetch).not.toHaveBeenCalled();
344 + });
345 +
346 + it('applies strict pinning requirements to every redirect hop', async () => {
347 + mockLookup
348 + .mockResolvedValueOnce([{ address: '93.184.216.34', family: 4 }] as never)
349 + .mockResolvedValueOnce([{ address: '151.101.1.140', family: 4 }] as never);
350 + mockFetch.mockResolvedValueOnce(
351 + new Response(null, {
352 + status: 302,
353 + headers: { location: 'https://cdn.example.com/file.pdf' },
354 + })
355 + );
356 + vi.stubEnv('NODE_USE_ENV_PROXY', '1');
357 + vi.stubEnv('HTTP_PROXY', '');
358 + vi.stubEnv('HTTPS_PROXY', 'http://proxy.example:3128');
359 + vi.stubEnv('NO_PROXY', '');
360 +
361 + await expect(
362 + ssrfSafeFetch('http://example.com/file.pdf', {}, { requirePinnedConnection: true })
363 + ).rejects.toBeInstanceOf(ComposioBlockedInternalUrlError);
364 +
365 + expect(mockFetch).toHaveBeenCalledTimes(1);
366 + expect(mockCreatePinnedDispatcher).toHaveBeenCalledTimes(1);
367 + });
368 +
369 it('validates and fetches a public URL', async () => {
370 resolvesTo('93.184.216.34');
371 const ok = new Response('data', { status: 200 });