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, 19:45 UTC
fix: apply automated code update (#3600)
This pull request contains an automated code update generated by Hex. Please review the diff carefully before merging. --- _Generated by Hex Security. Please review carefully before merging._ --------- Co-authored-by: Hex Security <255204168+hex-security-app[bot]@users.noreply.github.com> Co-authored-by: jkomyno <alberto@composio.dev>
hex-security-app[bot] committed
Jun 24, 2026 at 18:56 UTC
17fe8810591c6980416b407f7aa121a448f93d5f
8 files changed
+153
-20
ts/packages/cli/src/commands/py/commands/py.generate.cmd.ts
+1
-1
@@ -155,7 +155,7 @@ export function generatePythonTypeStubs({
155
const index = createToolkitIndex({ toolkits, typeableTools, triggerTypes, versionMap });
156
157
// Generate Python sources
158
- const sources = generatePythonSources({
158
+ const sources = yield* generatePythonSources({
159
banner: BANNER,
160
outputDir,
161
})(index);
ts/packages/cli/src/generation/python/generate.ts
+10
-7
@@ -1,6 +1,7 @@
1
-import path from 'node:path';
1
import type { ToolkitIndex } from 'src/generation/create-toolkit-index';
2
import type { SourceFile } from 'src/generation/types';
3
+import { Effect } from 'effect';
4
+import { safeOutputPath, type SafeOutputPathError } from 'src/generation/safe-output-path';
5
import { generatePythonToolkitSources } from './generate-toolkit-sources';
6
7
type GeneratePythonSourcesParams = {
@@ -9,13 +10,15 @@ type GeneratePythonSourcesParams = {
10
};
11
12
export function generatePythonSources(params: GeneratePythonSourcesParams) {
12
- return (index: ToolkitIndex): Array<SourceFile> => {
13
+ return (index: ToolkitIndex): Effect.Effect<Array<SourceFile>, SafeOutputPathError> => {
14
const toolkiteSources = generatePythonToolkitSources(params.banner)(index);
15
15
- return [
16
- ...toolkiteSources.map(
17
- ([filename, content]) => [path.join(params.outputDir, filename), content] as const
18
- ),
19
- ] as const;
16
+ return Effect.all(
17
+ toolkiteSources.map(([filename, content]) =>
18
+ safeOutputPath(params.outputDir, filename).pipe(
19
+ Effect.map(filePath => [filePath, content] as const)
20
+ )
21
+ )
22
+ );
23
};
24
}
ts/packages/cli/src/generation/safe-output-path.ts
new
+45
@@ -0,0 +1,45 @@
1
+import path from 'node:path';
2
+import { Data, Effect } from 'effect';
3
+
4
+export class SafeOutputPathError extends Data.TaggedError('generation/SafeOutputPathError')<{
5
+ readonly filename: string;
6
+ readonly outputDir: string;
7
+ readonly resolvedPath: string;
8
+ readonly message: string;
9
+}> {}
10
+
11
+/**
12
+ * Joins a generated filename to the output directory, ensuring the result stays
13
+ * within `outputDir`.
14
+ *
15
+ * Defense in depth against path traversal / arbitrary file write (CWE-22): even
16
+ * though toolkit slugs are validated at decode time, this guarantees that any
17
+ * filename derived from API-controlled data cannot escape the intended output
18
+ * directory via `..` segments or absolute paths.
19
+ *
20
+ * Fails if the resolved path is not contained within `outputDir`.
21
+ */
22
+export function safeOutputPath(
23
+ outputDir: string,
24
+ filename: string
25
+): Effect.Effect<string, SafeOutputPathError> {
26
+ const resolvedDir = path.resolve(outputDir);
27
+ const resolved = path.resolve(resolvedDir, filename);
28
+ const relative = path.relative(resolvedDir, resolved);
29
+ const isWithinOutputDir =
30
+ relative === '' ||
31
+ (!relative.startsWith(`..${path.sep}`) && relative !== '..' && !path.isAbsolute(relative));
32
+
33
+ if (path.isAbsolute(filename) || !isWithinOutputDir) {
34
+ return Effect.fail(
35
+ new SafeOutputPathError({
36
+ filename,
37
+ outputDir,
38
+ resolvedPath: resolved,
39
+ message: `Refusing unsafe generated filename: ${filename} resolves to ${resolved}`,
40
+ })
41
+ );
42
+ }
43
+
44
+ return Effect.succeed(path.join(outputDir, filename));
45
+}
ts/packages/cli/src/generation/typescript/generate.ts
+13
-8
@@ -1,12 +1,14 @@
1
import * as ts from '@composio/ts-builders';
2
import path from 'node:path';
3
+import { safeOutputPath, type SafeOutputPathError } from 'src/generation/safe-output-path';
4
import type { ToolkitIndex } from 'src/generation/create-toolkit-index';
5
+import type { SourceFile } from 'src/generation/types';
6
import { generateTypeScriptToolkitSources } from './generate-toolkit-sources';
7
import { generateIndexSource } from './generate-index-source';
8
import { Effect } from 'effect';
9
import type { GenerateTypeFromJsonSchemaError } from './generate-type-from-json-schema';
10
9
-type SourceFile = readonly [filename: string, content: string];
11
+type GenerateTypeScriptSourcesError = GenerateTypeFromJsonSchemaError | SafeOutputPathError;
12
13
type GenerateTypeScriptSourcesParams = {
14
banner: string;
@@ -18,7 +20,7 @@ type GenerateTypeScriptSourcesParams = {
20
export function generateTypeScriptSources(params: GenerateTypeScriptSourcesParams) {
21
return (
22
index: ToolkitIndex
21
- ): Effect.Effect<Array<SourceFile>, GenerateTypeFromJsonSchemaError, never> =>
23
+ ): Effect.Effect<Array<SourceFile>, GenerateTypeScriptSourcesError, never> =>
24
Effect.gen(function* () {
25
const toolkitSources = yield* generateTypeScriptToolkitSources(params.banner)(index);
26
@@ -26,12 +28,15 @@ export function generateTypeScriptSources(params: GenerateTypeScriptSourcesParam
28
const indexFilename = path.join(params.outputDir, 'index.ts');
29
30
if (!params.emitSingleFile) {
29
- return [
30
- ...toolkitSources.map(
31
- ([filename, content]) => [path.join(params.outputDir, filename), content] as const
32
- ),
33
- [indexFilename, indexSource] as const,
34
- ] as const;
31
+ const safeToolkitSources = yield* Effect.all(
32
+ toolkitSources.map(([filename, content]) =>
33
+ safeOutputPath(params.outputDir, filename).pipe(
34
+ Effect.map(filePath => [filePath, content] as const)
35
+ )
36
+ )
37
+ );
38
+
39
+ return [...safeToolkitSources, [indexFilename, indexSource] as const] as const;
40
}
41
42
const localToolkitsSources = toolkitSources.map(([_, content]) => content).join('\n');
ts/packages/cli/src/models/toolkits.ts
+18
-2
@@ -1,9 +1,25 @@
1
import { Brand, Schema } from 'effect';
2
import { JSONTransformSchema } from './utils/json-transform-schema';
3
4
+/**
5
+ * A toolkit slug used to derive generated source filenames.
6
+ *
7
+ * Restricted to a single, safe path segment (no `/`, `\`, or `..`) to prevent
8
+ * path traversal / arbitrary file write when the slug is interpolated into a
9
+ * filename and joined to the generator's output directory. See CWE-22.
10
+ */
11
+export const ToolkitSlug = Schema.Trim.pipe(
12
+ Schema.nonEmptyString(),
13
+ Schema.pattern(/^[a-z0-9_][a-z0-9_-]*$/, {
14
+ identifier: 'ToolkitSlug',
15
+ message: () =>
16
+ 'Toolkit slug must contain only lowercase letters, digits, underscores, and hyphens (no path separators)',
17
+ })
18
+);
19
+
20
export const Toolkit = Schema.Struct({
21
name: Schema.String, // "Gmail"
6
- slug: Schema.Trim.pipe(Schema.nonEmptyString()), // "gmail"
22
+ slug: ToolkitSlug, // "gmail"
23
auth_schemes: Schema.Array(Schema.String), // [ "OAUTH2", "BEARER_TOKEN" ]
24
composio_managed_auth_schemes: Schema.Array(Schema.String), // [ "OAUTH2" ]
25
is_local_toolkit: Schema.Boolean,
@@ -67,7 +83,7 @@ export type AuthConfigDetail = Schema.Schema.Type<typeof AuthConfigDetail>;
83
*/
84
export const ToolkitDetailed = Schema.Struct({
85
name: Schema.String,
70
- slug: Schema.Trim.pipe(Schema.nonEmptyString()),
86
+ slug: ToolkitSlug,
87
is_local_toolkit: Schema.Boolean,
88
composio_managed_auth_schemes: Schema.optionalWith(Schema.Array(Schema.String), {
89
default: () => [],
ts/packages/cli/src/services/composio-clients.ts
+8
-2
@@ -15,7 +15,13 @@ import {
15
import { Composio as _RawComposioClient, APIPromise } from '@composio/client';
16
import type { AuthConfigCreateParams } from '@composio/client/resources/auth-configs';
17
import type { ConnectedAccountListParams } from '@composio/client/resources/connected-accounts';
18
-import { Toolkit, Toolkits, ToolkitDetailed, type ToolkitSearchResult } from 'src/models/toolkits';
18
+import {
19
+ Toolkit,
20
+ Toolkits,
21
+ ToolkitDetailed,
22
+ ToolkitSlug,
23
+ type ToolkitSearchResult,
24
+} from 'src/models/toolkits';
25
import { AuthConfigItem, AuthConfigItems } from 'src/models/auth-configs';
26
import { ConnectedAccountItem, ConnectedAccountItems } from 'src/models/connected-accounts';
27
import { TriggerInstanceItems } from 'src/models/triggers';
@@ -251,7 +257,7 @@ export type ToolkitsResponse = Schema.Schema.Type<typeof ToolkitsResponse>;
257
// Similar to Toolkits, without auth_schemes, with auth_config_details instead
258
export const ToolkitRetrieveResponse = Schema.Struct({
259
name: Schema.String,
254
- slug: Schema.Trim.pipe(Schema.nonEmptyString()),
260
+ slug: ToolkitSlug,
261
is_local_toolkit: Schema.Boolean,
262
composio_managed_auth_schemes: Schema.optionalWith(Schema.Array(Schema.String), {
263
default: () => [],
ts/packages/cli/test/src/generation/safe-output-path.test.ts
new
+41
@@ -0,0 +1,41 @@
1
+import path from 'node:path';
2
+import { describe, expect, it, assert } from '@effect/vitest';
3
+import { Effect, Either } from 'effect';
4
+import { safeOutputPath, SafeOutputPathError } from 'src/generation/safe-output-path';
5
+
6
+describe('safeOutputPath', () => {
7
+ it.effect(
8
+ '[Given] a relative output directory and normal filename [Then] it returns a path in the same coordinate space',
9
+ Effect.fn(function* () {
10
+ const outputDir = 'generated';
11
+ const filePath = yield* safeOutputPath(outputDir, 'gmail.ts');
12
+
13
+ expect(filePath).toBe(path.join(outputDir, 'gmail.ts'));
14
+ expect(path.isAbsolute(filePath)).toBe(false);
15
+ })
16
+ );
17
+
18
+ it.effect(
19
+ '[Given] an absolute generated filename [Then] it fails through the Effect error channel',
20
+ Effect.fn(function* () {
21
+ const result = yield* safeOutputPath('generated', path.resolve('gmail.ts')).pipe(
22
+ Effect.either
23
+ );
24
+
25
+ assert(Either.isLeft(result));
26
+ expect(result.left).toBeInstanceOf(SafeOutputPathError);
27
+ expect(result.left.filename).toBe(path.resolve('gmail.ts'));
28
+ })
29
+ );
30
+
31
+ it.effect(
32
+ '[Given] a parent-directory generated filename [Then] it fails through the Effect error channel',
33
+ Effect.fn(function* () {
34
+ const result = yield* safeOutputPath('generated', '../gmail.ts').pipe(Effect.either);
35
+
36
+ assert(Either.isLeft(result));
37
+ expect(result.left).toBeInstanceOf(SafeOutputPathError);
38
+ expect(result.left.filename).toBe('../gmail.ts');
39
+ })
40
+ );
41
+});
ts/packages/cli/test/src/models/toolkits.test.ts
new
+17
@@ -0,0 +1,17 @@
1
+import { describe, expect, it } from '@effect/vitest';
2
+import { Effect } from 'effect';
3
+import toolkitsJson from 'test/__mocks__/toolkits.json' with { type: 'json' };
4
+import { toolkitsFromJSON } from 'src/models/toolkits';
5
+
6
+describe('ToolkitSlug', () => {
7
+ it.effect(
8
+ '[Given] cached toolkit data with underscore-prefixed slugs [Then] it decodes successfully',
9
+ Effect.fn(function* () {
10
+ const toolkits = yield* toolkitsFromJSON(JSON.stringify(toolkitsJson));
11
+
12
+ expect(toolkits.map(toolkit => toolkit.slug)).toEqual(
13
+ expect.arrayContaining(['_21risk', '_2chat'])
14
+ );
15
+ })
16
+ );
17
+});