@devries-cameron20 / composio Mirror · read-only / commits / 5ec0bdf40
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.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 11:00 UTC

fix(core): validate remote file destinations before downloading (#4621)

This PR: - builds on top of [#4487](https://github.com/ComposioHQ/composio/pull/4487) ([Glen review](https://app.tryglen.com/ComposioHQ/composio/pull/4487)) and carries forward the validation-before-download improvement from #4545. - moves `await this.buffer()` after destination validation and before directory creation, so invalid default filenames raise `ValidationError` without fetching content. - strengthens the existing invalid-path regression with a failing fetch mock and assertions that no request or directory creation occurs; adds a patch changeset for `@composio/core`. Validation: the seven invalid-path cases failed before the fix; all 103 focused `RemoteFile` and `safePath` tests pass afterward. Core typecheck (including type tests), focused Oxlint/Prettier checks, and agent-guidance, skill-routing, and changeset validators pass.

Alberto Schiabel committed Sep 24, 2026 at 13:24 UTC 5ec0bdf40769c193ff148fbe648977b5608bb1e3
3 files changed +11 -2
.changeset/remote-file-validate-before-download.md new
+5
@@ -0,0 +1,5 @@
1 +---
2 +'@composio/core': patch
3 +---
4 +
5 +Validate the default destination in `RemoteFile.save()` before downloading content. Invalid mount paths now raise `ValidationError` without a network request, even when the download would fail.
ts/packages/core/src/models/RemoteFile.ts
+2 -1
@@ -185,7 +185,6 @@ export class RemoteFile {
185 );
186 }
187
188 - const content = await this.buffer();
188 const homeDir = platform.homedir();
189 if (!homeDir) {
190 throw new Error('Cannot determine save location: home directory is not available');
@@ -200,6 +199,8 @@ export class RemoteFile {
199 const savePath =
200 path ?? platform.joinPath(defaultDir, safeBasename(this.mountRelativePath, 'mount path'));
201
202 + const content = await this.buffer();
203 +
204 const dir = path != null ? getParentDir(savePath) : defaultDir;
205 if (dir && !platform.existsSync(dir)) {
206 platform.mkdirSync(dir);
ts/packages/core/test/models/RemoteFile.test.ts
+4 -1
@@ -337,13 +337,16 @@ describe('RemoteFile', () => {
337 // parent), which previously surfaced as an unhandled `EISDIR` from
338 // `writeFileSync` after the directory had already been created.
339 it.each(['', '.', 'sub/.', 'foo/..', '..', '\u00a0.\u00a0', '\u2007..\u2007'])(
340 - 'should reject mountRelativePath %j with a ValidationError',
340 + 'should reject mountRelativePath %j before downloading',
341 async mountRelativePath => {
342 const { platform } = await import('../../src/platform/node');
343 const file = new RemoteFile({ ...validCamelCaseData, mountRelativePath });
344 + const fetchMock = vi.fn().mockRejectedValue(new Error('Download unavailable'));
345 + globalThis.fetch = fetchMock;
346
347 await expect(file.save()).rejects.toThrow(ValidationError);
348 await expect(file.save()).rejects.toThrow(/leaves no usable basename/);
349 + expect(fetchMock).not.toHaveBeenCalled();
350 expect(platform.existsSync(composioDir)).toBe(false);
351 }
352 );