@devries-cameron20 / composio-1 / commits / 9d0cb2cf8
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): cap remote file downloads in tool uploads (SEC-908) (#4417)

## Summary AppSecure SEC-908 reported that remote files fetched from user-supplied URLs were read into memory with no size cap. The core SDK (`fileUtils.node.ts`, `RemoteFile.ts`, `ToolRouterSessionFileMount.ts`) and the Python SDK already stream through a 100 MiB limit. The CLI's tool-input upload path (`ts/packages/cli/src/services/tool-file-uploads.ts`) was the last remaining sink: `readFileFromUrl` still did `response.arrayBuffer()`, so a large or never-ending response could exhaust memory before the presigned upload was even requested. Fixes SEC-908 (internal tracker). ## Changes - `@composio/core` exports `readResponseBodyWithLimit` and `MAX_URL_UPLOAD_SIZE_BYTES`, next to the existing `assertSafeFileUploadPath` export, so downstream packages reuse the one bounded reader. - CLI `readFileFromUrl` uses it in place of `response.arrayBuffer()`; behaviour is unchanged below the cap. - Regression test: a response declaring a body above the cap is rejected before `createPresignedURL` is called. - Changeset for `@composio/core` (patch). `@composio/cli` is in the changeset ignore list. ## Type of change - [x] Bug fix - [ ] New feature - [ ] Refactor/Chore - [ ] Documentation - [ ] Breaking change ## How Has This Been Tested? ``` pnpm --filter @composio/core build pnpm --filter @composio/core exec vitest run test/utils/readResponseBody.test.ts Tests 4 passed (4) pnpm --filter @composio/cli exec vitest run test/src/services/tool-file-uploads.test.ts Tests 8 passed (8) pnpm exec prettier --check <touched files> pnpm exec oxlint <touched files> ``` `tsc --noEmit` on the CLI package reports the same pre-existing errors on `next` and none in the touched files. Node 24.17.0, pnpm 11.8.0 via mise. ## Screenshots (if applicable) ## Checklist - [x] I have read the Code of Conduct and this PR adheres to it - [x] I ran linters/tests locally and they passed - [x] I updated documentation as needed - [x] I added tests or explain why not applicable - [x] I added a changeset if this change affects published packages ## Additional context The other files AppSecure listed for this finding were already capped on `next` (core: ecd0861, 8a56383; python: 54d07dc); this PR closes the residual. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>

Saransh Rana committed Sep 10, 2026 at 19:27 UTC 9d0cb2cf89eeb21e7d06e87a703d2673d52e9ede
4 files changed +58 -2
.changeset/read-response-body-export.md new
+5
@@ -0,0 +1,5 @@
1 +---
2 +'@composio/core': patch
3 +---
4 +
5 +Export `readResponseBodyWithLimit` and `MAX_URL_UPLOAD_SIZE_BYTES` so downstream packages can apply the SDK's 100 MiB cap when they download a file from a user-supplied URL. The CLI's tool-input file uploads now use it instead of buffering the whole response.
ts/packages/cli/src/services/tool-file-uploads.ts
+5 -2
@@ -6,7 +6,7 @@
6 import type * as FileSystem from '@effect/platform/FileSystem';
7 import type * as Path from '@effect/platform/Path';
8 import type { Composio as RawComposioClient } from '@composio/client';
9 -import { assertSafeFileUploadPath } from '@composio/core';
9 +import { assertSafeFileUploadPath, readResponseBodyWithLimit } from '@composio/core';
10 import { ssrfSafeFetch } from '@composio/core/utils/ssrf-guard';
11 import { Cause, Data, Effect, Exit, Predicate } from 'effect';
12 import { guessToolkitFromToolSlug } from 'src/utils/toolkit-from-tool-slug';
@@ -155,7 +155,10 @@ const readFileFromUrl = async (path: Path.Path, url: string) => {
155 });
156 }
157
158 - const bytes = new Uint8Array(await response.arrayBuffer());
158 + // Same cap as the core SDK's URL uploads: a remote server must not be able
159 + // to exhaust memory with an oversized or never-ending body. Copied into a
160 + // fresh ArrayBuffer-backed view for the same reason as readFileFromDisk.
161 + const bytes = new Uint8Array(await readResponseBodyWithLimit(response));
162 const parsedUrl = new URL(url);
163 const fileName = path.basename(parsedUrl.pathname) || `file-${Date.now()}`;
164
ts/packages/cli/test/src/services/tool-file-uploads.test.ts
+44
@@ -11,6 +11,7 @@ import { Composio as RawComposioClient } from '@composio/client';
11 import {
12 ComposioBlockedInternalUrlError,
13 ComposioSensitiveFilePathBlockedError,
14 + MAX_URL_UPLOAD_SIZE_BYTES,
15 } from '@composio/core';
16 import { schemaHasFileUploadable, uploadToolInputFiles } from 'src/services/tool-file-uploads';
17
@@ -236,3 +237,46 @@ describe('uploadToolInputFiles — URL SSRF boundary', () => {
237 );
238 });
239 });
240 +
241 +describe('uploadToolInputFiles — URL download size cap', () => {
242 + afterEach(() => {
243 + vi.unstubAllGlobals();
244 + vi.restoreAllMocks();
245 + });
246 +
247 + it.effect('rejects a remote file that declares a body above the cap before buffering it', () => {
248 + const createPresignedURL = vi.fn();
249 + const client = makeClient(createPresignedURL);
250 + const oversized = String(MAX_URL_UPLOAD_SIZE_BYTES + 1);
251 + vi.stubGlobal(
252 + 'fetch',
253 + vi.fn(
254 + async () =>
255 + new Response('not the real body', {
256 + status: 200,
257 + headers: { 'content-length': oversized, 'content-type': 'application/octet-stream' },
258 + })
259 + )
260 + );
261 +
262 + return Effect.gen(function* () {
263 + const fsApi = yield* FileSystem.FileSystem;
264 + const pathApi = yield* Path.Path;
265 +
266 + yield* Effect.promise(() =>
267 + expect(
268 + uploadToolInputFiles({
269 + fs: fsApi,
270 + path: pathApi,
271 + toolSlug: 'GMAIL_SEND_EMAIL',
272 + arguments_: { attachment: 'https://1.1.1.1/large.bin' },
273 + inputSchema,
274 + client,
275 + })
276 + ).rejects.toThrow(/exceeds maximum allowed size/)
277 + );
278 +
279 + expect(createPresignedURL).not.toHaveBeenCalled();
280 + }).pipe(Effect.provide(Layer.mergeAll(BunFileSystem.layer, BunPath.layer)));
281 + });
282 +});
ts/packages/core/src/index.ts
+4
@@ -33,6 +33,10 @@ export {
33 isBlockedSensitiveFileUploadPath,
34 BUILTIN_FILE_UPLOAD_PATH_DENY_SEGMENTS,
35 } from './utils/sensitiveFileUploadPaths';
36 +// Bounded response reader for files fetched from user-supplied URLs. Exported
37 +// for the same reason as the denylist guard above: downstream packages read
38 +// remote files too, and every such read must enforce the same size cap.
39 +export { readResponseBodyWithLimit, MAX_URL_UPLOAD_SIZE_BYTES } from './utils/readResponseBody';
40 export {
41 sanitizeSchemaPropertyKeys,
42 restoreOriginalKeys,