@devries-cameron20 / composio Mirror · read-only / commits / 7677f8496
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, 14:45 UTC

fix(core): block sensitive upload paths hidden behind a symlinked directory

The sensitive-file-upload denylist matched deny segments only against the symlink-resolved path. That catches a benign name pointing at a secret (`~/innocent -> ~/.aws/creds`, which the existing test covers) but misses the inverse: a sensitive directory that is itself a symlink to a target without the denied segment. `~/.claude -> /state/claude` resolves to `/state/claude/...`, which contains no `.claude` segment, so the denylist let it through — and `.claude` is on the list precisely because it "may contain API keys". That layout is not exotic. Dotfile managers (chezmoi, stow, yadm) and containerised home directories produce it routinely; Composio's own agent sandbox image does. For those users the control was silently inactive. The repository's own test asserted the blocked behaviour and has been failing wherever `~/.claude` is a symlink. CI never caught it because `~/.claude` does not exist on the runners, so no realpath happens and the written path keeps its `.claude` segment. Match both the written and the resolved path, for directory segments and for the basename check, since either one can be the one carrying the denied name. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

composio-zen[bot] committed Aug 23, 2026 at 17:10 UTC 7677f849687b35eda9e4574f36204854646fc3a1
2 files changed +94 -9
ts/packages/core/src/utils/sensitiveFileUploadPaths.ts
+36 -9
@@ -31,10 +31,29 @@ const SECRET_LIKE_BASENAME = /^(\.env(\.|$)|\.netrc$|\.pgpass$)/i;
31 /** Default SSH private key basenames (public keys like id_rsa.pub are allowed). */
32 const DEFAULT_PRIVATE_KEY_BASENAME = /^id_(rsa|ed25519|ecdsa|dsa|ecdsa_sk)(\.old)?$/i;
33
34 +const splitSegments = (aPath: string): string[] => aPath.split(/[/\\]+/).filter(Boolean);
35 +
36 /**
37 * Returns normalized path segments, resolving symlinks when the path exists.
38 + *
39 + * Both the written path and the symlink-resolved one are returned, because a
40 + * denied segment can be hidden by a symlink in either direction:
41 + *
42 + * - `~/innocent-name` -> `~/nested/.aws/creds` hides `.aws` from the written
43 + * path, so the denylist has to see the resolved one.
44 + * - `~/.claude` -> `/state/claude` hides `.claude` from the *resolved* path,
45 + * so the denylist also has to see the written one. Dotfile managers
46 + * (chezmoi, stow, yadm) and containerised home directories produce exactly
47 + * this layout.
48 + *
49 + * Matching only the resolved path silently turns the denylist off for the
50 + * second case.
51 */
37 -function normalizePath(filePath: string): { resolvedPath: string; segments: string[] } {
52 +function normalizePath(filePath: string): {
53 + resolvedPath: string;
54 + segments: string[];
55 + writtenSegments: string[];
56 +} {
57 const absolute = platform.resolvePath(filePath);
58 let resolved = absolute;
59 try {
@@ -46,7 +65,8 @@ function normalizePath(filePath: string): { resolvedPath: string; segments: stri
65 }
66 return {
67 resolvedPath: resolved,
49 - segments: resolved.split(/[/\\]+/).filter(Boolean),
68 + segments: splitSegments(resolved),
69 + writtenSegments: splitSegments(absolute),
70 };
71 }
72
@@ -65,7 +85,7 @@ function getSensitiveFileUploadPathBlockReason(
85 filePath: string,
86 additionalDenySegments?: string[]
87 ): string | null {
68 - const { resolvedPath, segments } = normalizePath(filePath);
88 + const { resolvedPath, segments, writtenSegments } = normalizePath(filePath);
89 const isCaseSensitive = platform.isFileSystemCaseSensitive?.(resolvedPath) ?? true;
90 const normalizeSegment = (segment: string) => (isCaseSensitive ? segment : segment.toLowerCase());
91 const deny = new Set(
@@ -75,15 +95,22 @@ function getSensitiveFileUploadPathBlockReason(
95 ].map(normalizeSegment)
96 );
97
78 - const segmentsForMatch = isCaseSensitive ? segments : segments.map(normalizeSegment);
79 - for (let i = 0; i < segments.length; i++) {
80 - if (deny.has(segmentsForMatch[i]!)) {
81 - return `path segment "${segments[i]}" is in the sensitive file upload denylist`;
98 + for (const candidate of [segments, writtenSegments]) {
99 + const segmentsForMatch = isCaseSensitive ? candidate : candidate.map(normalizeSegment);
100 + for (let i = 0; i < candidate.length; i++) {
101 + if (deny.has(segmentsForMatch[i]!)) {
102 + return `path segment "${candidate[i]}" is in the sensitive file upload denylist`;
103 + }
104 }
105 }
106
85 - const basename = segments.length > 0 ? segments[segments.length - 1] : '';
86 - if (basename) {
107 + // Same two directions as the segment scan: `~/.env -> /state/config` hides a
108 + // denied basename from the resolved path, and a symlink pointing *at* a
109 + // credential file hides it from the written one.
110 + const basenames = [segments.at(-1), writtenSegments.at(-1)].filter(
111 + (name): name is string => !!name
112 + );
113 + for (const basename of basenames) {
114 if (SECRET_LIKE_BASENAME.test(basename) || DEFAULT_PRIVATE_KEY_BASENAME.test(basename)) {
115 return `file name "${basename}" looks like a credential, env, or private key file`;
116 }
ts/packages/core/test/utils/sensitiveFileUploadPaths.test.ts
+58
@@ -93,4 +93,62 @@ describe('sensitiveFileUploadPaths', () => {
93 rmSync(root, { recursive: true, force: true });
94 }
95 });
96 +
97 + // The inverse of the case above: realpath moves the denied segment *out* of
98 + // the path instead of into it. Dotfile managers (chezmoi, stow, yadm) and
99 + // containerised home directories lay `~/.claude -> /state/claude` out exactly
100 + // this way, so matching only the resolved path turned the denylist off for
101 + // them.
102 + it('blocks a sensitive directory that is itself a symlink to a plain path', () => {
103 + const root = mkdtempSync(path.join(os.tmpdir(), 'composio-symlink-dir-'));
104 + try {
105 + const store = path.join(root, 'state', 'claude');
106 + mkdirSync(store, { recursive: true });
107 + writeFileSync(path.join(store, 'settings.json'), '{}');
108 + const home = path.join(root, 'home');
109 + mkdirSync(home, { recursive: true });
110 + const link = path.join(home, '.claude');
111 + symlinkSync(store, link);
112 +
113 + expect(isBlockedSensitiveFileUploadPath(path.join(link, 'settings.json'))).toBe(true);
114 + expect(() => assertSafeFileUploadPath(path.join(link, 'settings.json'))).toThrow();
115 + } finally {
116 + rmSync(root, { recursive: true, force: true });
117 + }
118 + });
119 +
120 + // Same hiding trick applied to the basename rather than a directory segment:
121 + // the written name is `.env`, the resolved one is not.
122 + it('blocks a denied basename whose symlink target is named innocuously', () => {
123 + const root = mkdtempSync(path.join(os.tmpdir(), 'composio-symlink-base-'));
124 + try {
125 + const store = path.join(root, 'store');
126 + mkdirSync(store, { recursive: true });
127 + const target = path.join(store, 'plain-config');
128 + writeFileSync(target, 'SECRET=1');
129 + const project = path.join(root, 'project');
130 + mkdirSync(project, { recursive: true });
131 + const link = path.join(project, '.env');
132 + symlinkSync(target, link);
133 +
134 + expect(isBlockedSensitiveFileUploadPath(link)).toBe(true);
135 + } finally {
136 + rmSync(root, { recursive: true, force: true });
137 + }
138 + });
139 +
140 + it('still allows an ordinary file reached through a symlinked directory', () => {
141 + const root = mkdtempSync(path.join(os.tmpdir(), 'composio-symlink-ok-'));
142 + try {
143 + const store = path.join(root, 'store');
144 + mkdirSync(store, { recursive: true });
145 + writeFileSync(path.join(store, 'document.pdf'), 'x');
146 + const link = path.join(root, 'docs');
147 + symlinkSync(store, link);
148 +
149 + expect(isBlockedSensitiveFileUploadPath(path.join(link, 'document.pdf'))).toBe(false);
150 + } finally {
151 + rmSync(root, { recursive: true, force: true });
152 + }
153 + });
154 });