@devries-cameron20 / composio-1 / commits / b847a2cfd
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(core): stop misclassifying local paths starting with "http" as URLs (#3766)

This PR: - fixes a `startsWith('http')` check in the TypeScript SDK that misclassified local paths such as `http_export/report.csv` or `http_backup/.ssh/id_rsa` as URLs - the misclassification routed those paths through the URL-fetch branch, which skips both the upload allowlist (`assertPathInsideUploadDirs`) and the sensitive-path denylist (`assertSafeFileUploadPath`, added in #3763 for GHSA-hp3h-89pf-5q58) - replaces the naive prefix check with `isHttpUrl()`, a `new URL()`-based check in `fileUtils.node.ts`, matching the Python SDK's existing `_is_url()` behavior (`urlparse` + scheme check), which was not affected by this bug - updates the three call sites that used the naive check: `fileUtils.node.ts` (`readFile`, `getFileDataAfterUploadingToS3`) and `FileToolModifier.node.ts` (`beforeFileUpload` source classification) - adds a regression test asserting a path like `http_export/.aws/creds` is still blocked by the sensitive-path denylist rather than routed to `fetch`

Alberto Schiabel committed Jul 7, 2026 at 18:03 UTC b847a2cfd3e2d722d6b3a29cd164f039d316c846
4 files changed +46 -3
ts/packages/core/src/utils/fileUtils.node.ts
+21 -2
@@ -39,6 +39,25 @@ export type GetFileDataAfterUploadingToS3Options = {
39 signal?: AbortSignal;
40 };
41
42 +/**
43 + * Checks whether `value` is an absolute http(s) URL rather than a local path.
44 + *
45 + * A bare `startsWith('http')` check also matches local paths like
46 + * `http_export/report.csv` or `httpdocs/.env`, which routes them into the URL
47 + * fetch branch and skips the allowlist/denylist checks in
48 + * {@link getFileDataAfterUploadingToS3}. `new URL()` requires a real scheme
49 + * (`http:` or `https:`) followed by `//`, so relative-looking paths correctly
50 + * fail to parse and are treated as local.
51 + */
52 +export const isHttpUrl = (value: string): boolean => {
53 + try {
54 + const url = new URL(value);
55 + return url.protocol === 'http:' || url.protocol === 'https:';
56 + } catch {
57 + return false;
58 + }
59 +};
60 +
61 // Helper function to get file extension from MIME type
62 const getExtensionFromMimeType = (mimeType: string): string => {
63 const mimeToExt: Record<string, string> = {
@@ -248,7 +267,7 @@ const readFile = async (
267 mimeType: file.type,
268 };
269 } else if (typeof file === 'string') {
251 - if (file.startsWith('http')) {
270 + if (isHttpUrl(file)) {
271 return await readFileContentFromURL(file, signal);
272 } else {
273 return await readFileContent(file);
@@ -273,7 +292,7 @@ export const getFileDataAfterUploadingToS3 = async (
292 throw new Error('Either path or blob must be provided');
293 }
294
276 - const isLocalPath = typeof file === 'string' && !file.startsWith('http');
295 + const isLocalPath = typeof file === 'string' && !isHttpUrl(file);
296
297 if (isLocalPath && fileUploadAllowlist !== undefined) {
298 assertPathInsideUploadDirs(file as string, fileUploadAllowlist);
ts/packages/core/src/utils/modifiers/FileToolModifier.node.ts
+2 -1
@@ -18,6 +18,7 @@ import type { beforeFileUploadModifier } from '../../types/modifiers.types';
18 import {
19 downloadFileFromS3,
20 getFileDataAfterUploadingToS3,
21 + isHttpUrl,
22 type GetFileDataAfterUploadingToS3Options,
23 } from '../fileUtils.node';
24 import {
@@ -150,7 +151,7 @@ const hydrateFiles = async (
151 if (typeof value === 'string') {
152 // Match the URL/local-path split used downstream in
153 // getFileDataAfterUploadingToS3 so the hook sees the same categorisation.
153 - const source = value.startsWith('http') ? 'url' : 'path';
154 + const source = isHttpUrl(value) ? 'url' : 'path';
155 const pathOrUrl = await runBeforeFileUpload(value, source);
156 logger.debug(`Uploading file "${pathOrUrl}"`);
157 return getFileDataAfterUploadingToS3(pathOrUrl, {
ts/packages/core/test/tools/fileModifiers.test.ts
+8
@@ -16,6 +16,14 @@ import { mockClient } from '../utils/mocks/client.mock';
16 vi.mock('../../src/utils/fileUtils.node', () => ({
17 downloadFileFromS3: vi.fn(),
18 getFileDataAfterUploadingToS3: vi.fn(),
19 + isHttpUrl: (value: string): boolean => {
20 + try {
21 + const url = new URL(value);
22 + return url.protocol === 'http:' || url.protocol === 'https:';
23 + } catch {
24 + return false;
25 + }
26 + },
27 }));
28
29 describe('FileToolModifier', () => {
ts/packages/core/test/utils/fileUtils.test.ts
+15
@@ -431,6 +431,21 @@ describe('fileUtils', () => {
431 ).rejects.toThrow(ComposioSensitiveFilePathBlockedError);
432 });
433
434 + it('treats a local path that merely starts with "http" as a path, not a URL', async () => {
435 + // Regression test: a naive `.startsWith('http')` check would misclassify
436 + // this as a URL and skip the local-path denylist entirely.
437 + await expect(
438 + getFileDataAfterUploadingToS3(path.join('http_export', '.aws', 'creds'), {
439 + toolSlug: 'test-tool',
440 + toolkitSlug: 'test-toolkit',
441 + client: mockClient,
442 + })
443 + ).rejects.toThrow(ComposioSensitiveFilePathBlockedError);
444 +
445 + // It must not have been routed through the URL-fetch branch.
446 + expect(mockFetch).not.toHaveBeenCalled();
447 + });
448 +
449 it('should handle fetch errors for URLs', async () => {
450 mockFetch.mockResolvedValue({
451 ok: false,