Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
fix(cli): cap remote file downloads in tool uploads (SEC-908) (#4417)
Saransh Rana9d0cb2cf89ee
diff --git a/.changeset/read-response-body-export.md b/.changeset/read-response-body-export.mdnew file mode 100644index 000000000..fb9394f29--- /dev/null+++ b/.changeset/read-response-body-export.md@@ -0,0 +1,5 @@+---+'@composio/core': patch+---++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.diff --git a/ts/packages/cli/src/services/tool-file-uploads.ts b/ts/packages/cli/src/services/tool-file-uploads.tsindex a33102354..4b4ae2163 100644--- a/ts/packages/cli/src/services/tool-file-uploads.ts+++ b/ts/packages/cli/src/services/tool-file-uploads.ts@@ -6,7 +6,7 @@import type * as FileSystem from '@effect/platform/FileSystem';import type * as Path from '@effect/platform/Path';import type { Composio as RawComposioClient } from '@composio/client';-import { assertSafeFileUploadPath } from '@composio/core';+import { assertSafeFileUploadPath, readResponseBodyWithLimit } from '@composio/core';import { ssrfSafeFetch } from '@composio/core/utils/ssrf-guard';import { Cause, Data, Effect, Exit, Predicate } from 'effect';import { guessToolkitFromToolSlug } from 'src/utils/toolkit-from-tool-slug';@@ -155,7 +155,10 @@ const readFileFromUrl = async (path: Path.Path, url: string) => {});}- const bytes = new Uint8Array(await response.arrayBuffer());+ // Same cap as the core SDK's URL uploads: a remote server must not be able+ // to exhaust memory with an oversized or never-ending body. Copied into a+ // fresh ArrayBuffer-backed view for the same reason as readFileFromDisk.+ const bytes = new Uint8Array(await readResponseBodyWithLimit(response));const parsedUrl = new URL(url);const fileName = path.basename(parsedUrl.pathname) || `file-${Date.now()}`;diff --git a/ts/packages/cli/test/src/services/tool-file-uploads.test.ts b/ts/packages/cli/test/src/services/tool-file-uploads.test.tsindex e7913fc52..36b7c1e02 100644--- a/ts/packages/cli/test/src/services/tool-file-uploads.test.ts+++ b/ts/packages/cli/test/src/services/tool-file-uploads.test.ts@@ -11,6 +11,7 @@ import { Composio as RawComposioClient } from '@composio/client';import {ComposioBlockedInternalUrlError,ComposioSensitiveFilePathBlockedError,+ MAX_URL_UPLOAD_SIZE_BYTES,} from '@composio/core';import { schemaHasFileUploadable, uploadToolInputFiles } from 'src/services/tool-file-uploads';@@ -236,3 +237,46 @@ describe('uploadToolInputFiles — URL SSRF boundary', () => {);});});++describe('uploadToolInputFiles — URL download size cap', () => {+ afterEach(() => {+ vi.unstubAllGlobals();+ vi.restoreAllMocks();+ });++ it.effect('rejects a remote file that declares a body above the cap before buffering it', () => {+ const createPresignedURL = vi.fn();+ const client = makeClient(createPresignedURL);+ const oversized = String(MAX_URL_UPLOAD_SIZE_BYTES + 1);+ vi.stubGlobal(+ 'fetch',+ vi.fn(+ async () =>+ new Response('not the real body', {+ status: 200,+ headers: { 'content-length': oversized, 'content-type': 'application/octet-stream' },+ })+ )+ );++ return Effect.gen(function* () {+ const fsApi = yield* FileSystem.FileSystem;+ const pathApi = yield* Path.Path;++ yield* Effect.promise(() =>+ expect(+ uploadToolInputFiles({+ fs: fsApi,+ path: pathApi,+ toolSlug: 'GMAIL_SEND_EMAIL',+ arguments_: { attachment: 'https://1.1.1.1/large.bin' },+ inputSchema,+ client,+ })+ ).rejects.toThrow(/exceeds maximum allowed size/)+ );++ expect(createPresignedURL).not.toHaveBeenCalled();+ }).pipe(Effect.provide(Layer.mergeAll(BunFileSystem.layer, BunPath.layer)));+ });+});diff --git a/ts/packages/core/src/index.ts b/ts/packages/core/src/index.tsindex 27ba21561..dbd491633 100644--- a/ts/packages/core/src/index.ts+++ b/ts/packages/core/src/index.ts@@ -33,6 +33,10 @@ export {isBlockedSensitiveFileUploadPath,BUILTIN_FILE_UPLOAD_PATH_DENY_SEGMENTS,} from './utils/sensitiveFileUploadPaths';+// Bounded response reader for files fetched from user-supplied URLs. Exported+// for the same reason as the denylist guard above: downstream packages read+// remote files too, and every such read must enforce the same size cap.+export { readResponseBodyWithLimit, MAX_URL_UPLOAD_SIZE_BYTES } from './utils/readResponseBody';export {sanitizeSchemaPropertyKeys,restoreOriginalKeys,