@devries-cameron20 / composio Mirror · read-only / commits / 2dc9ef34d
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, 18:30 UTC

fix(cli): remove `new Function()` eval from JSON-ish input parsing (#3878)

This PR: - removes an in-process arbitrary-code-execution surface: `parse-json-ish.ts` fell back to `Function("return (…)")()` for any `tools execute --data`, `listen --params`, or `proxy` body value that failed JSON and comment-JSON parsing — the CLI is agent-facing and `--data` also accepts `@file` and stdin, so crafted or prompt-injected input reached the eval - lands the parser in its final consolidated shape: `src/utils/parse-json.ts` parses JSON5 (unquoted keys, single quotes, trailing commas, comments) without evaluating anything and returns `Either` with a typed `JsonParsingError` - consolidates the `effect-errors` read-json duplicates onto the same parser and swaps `comment-json` for `json5` (the stack's only lockfile change) - pins code-execution probes in unit tests (`new Date()`, computed expressions, `globalThis` writes are rejected, never evaluated) - intentional narrowing: JS expressions such as `1+1` that only worked because of the eval now fail with a parse error; proxy bodies that are not JSON5 records fall back to the raw string --- **Stack** (re-slice of https://github.com/ComposioHQ/composio/pull/3859; each PR targets its parent and auto-retargets to `next` as parents merge): 1. https://github.com/ComposioHQ/composio/pull/3877 — guidelines + inert rule groups 2. https://github.com/ComposioHQ/composio/pull/3878 — `new Function()` eval security fix ← **this PR** 3. https://github.com/ComposioHQ/composio/pull/3879 — behavioral fix pack 4. https://github.com/ComposioHQ/composio/pull/3880 — platform-imports rule + migration 5. https://github.com/ComposioHQ/composio/pull/3881 — terminal-streams rule + TerminalUI boundary 6. https://github.com/ComposioHQ/composio/pull/3882 — descriptor seam + zod→Schema 7. https://github.com/ComposioHQ/composio/pull/3883 — test-tree lint + deterministic suites 8. https://github.com/ComposioHQ/composio/pull/3884 — typed error boundaries + v4 seams 9. https://github.com/ComposioHQ/composio/pull/3885 — try/catch+env ban + boundary ratchet On stacked bases CI runs lint/build and the CLI Docker e2e job; unit tests and typecheck are verified locally per PR and re-verified by full CI when each PR is retargeted to `next`.

Alberto Schiabel committed Jul 21, 2026 at 11:14 UTC 2dc9ef34d0d63efb890a34b4fab8591877de06c7
12 files changed +146 -105
pnpm-lock.yaml
+10 -17
@@ -1165,9 +1165,6 @@ importers:
1165 '@zed-industries/codex-acp':
1166 specifier: ^0.16.0
1167 version: 0.16.0
1168 - comment-json:
1169 - specifier: ^5.0.0
1170 - version: 5.0.0
1168 effect:
1169 specifier: 'catalog:'
1170 version: 3.21.4
@@ -1180,6 +1177,9 @@ importers:
1177 js-tiktoken:
1178 specifier: ^1.0.21
1179 version: 1.0.21
1180 + json5:
1181 + specifier: ^2.2.3
1182 + version: 2.2.3
1183 open:
1184 specifier: ^11.0.0
1185 version: 11.0.0
@@ -4338,9 +4338,6 @@ packages:
4338 argparse@2.0.1:
4339 resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==}
4340
4341 - array-timsort@1.0.3:
4342 - resolution: {integrity: sha512-/+3GRL7dDAGEfM6TseQk/U+mi18TU2Ms9I3UlLdUMhz2hbvGNTKdj9xniwXfUqgYhHxRx0+8UnKkvlNwVU+cWQ==}
4343 -
4341 array-union@2.1.0:
4342 resolution: {integrity: sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==}
4343 engines: {node: '>=8'}
@@ -4534,10 +4531,6 @@ packages:
4531 resolution: {integrity: sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==}
4532 engines: {node: '>=14'}
4533
4537 - comment-json@5.0.0:
4538 - resolution: {integrity: sha512-uiqLcOiVDJtBP8WGkZHEP+FZIhTzP1dxvn59EfoYUi9gqupjrBWVQkO2atDrbnKPwLeotFYDsuNb26uBMqB+hw==}
4539 - engines: {node: '>= 6'}
4540 -
4534 concat-map@0.0.1:
4535 resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==}
4536
@@ -5454,6 +5447,11 @@ packages:
5447 json-stable-stringify-without-jsonify@1.0.1:
5448 resolution: {integrity: sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==}
5449
5450 + json5@2.2.3:
5451 + resolution: {integrity: sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==}
5452 + engines: {node: '>=6'}
5453 + hasBin: true
5454 +
5455 jsonfile@4.0.0:
5456 resolution: {integrity: sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==}
5457
@@ -9894,8 +9892,6 @@ snapshots:
9892
9893 argparse@2.0.1: {}
9894
9897 - array-timsort@1.0.3: {}
9898 -
9895 array-union@2.1.0: {}
9896
9897 assertion-error@2.0.1: {}
@@ -10086,11 +10082,6 @@ snapshots:
10082
10083 commander@10.0.1: {}
10084
10089 - comment-json@5.0.0:
10090 - dependencies:
10091 - array-timsort: 1.0.3
10092 - esprima: 4.0.1
10093 -
10085 concat-map@0.0.1: {}
10086
10087 consola@3.4.2: {}
@@ -10978,6 +10969,8 @@ snapshots:
10969
10970 json-stable-stringify-without-jsonify@1.0.1: {}
10971
10972 + json5@2.2.3: {}
10973 +
10974 jsonfile@4.0.0:
10975 optionalDependencies:
10976 graceful-fs: 4.2.11
ts/packages/cli/package.json
+1 -1
@@ -94,11 +94,11 @@
94 "@modelcontextprotocol/sdk": "catalog:",
95 "@zed-industries/claude-code-acp": "^0.16.2",
96 "@zed-industries/codex-acp": "^0.16.0",
97 - "comment-json": "^5.0.0",
97 "effect": "catalog:",
98 "extract-zip": "^2.0.1",
99 "indent-string": "^5.0.0",
100 "js-tiktoken": "^1.0.21",
101 + "json5": "^2.2.3",
102 "open": "^11.0.0",
103 "openapi-typescript": "^7.13.0",
104 "picocolors": "catalog:",
ts/packages/cli/src/commands/listen.cmd.ts
+11 -18
@@ -1,7 +1,7 @@
1 import { Args, Command, Options } from '@effect/cli';
2 import { FileSystem } from '@effect/platform';
3 import type { Composio as RawComposioClient } from '@composio/client';
4 -import { Deferred, Effect, Option, Runtime } from 'effect';
4 +import { Deferred, Effect, Either, Option, Runtime } from 'effect';
5 import path from 'node:path';
6 import { requireAuth } from 'src/effects/require-auth';
7 import { resolveOptionalTextInput } from 'src/effects/resolve-optional-text-input';
@@ -20,7 +20,7 @@ import {
20 formatConnectedAccountChoices,
21 resolveConnectedAccountSelection,
22 } from 'src/services/connected-account-selection';
23 -import { parseJsonIsh } from 'src/utils/parse-json-ish';
23 +import { parseJsonRecord } from 'src/utils/parse-json';
24 import { toolkitFromToolSlug } from 'src/utils/toolkit-from-tool-slug';
25 import { ComposioCliUserConfig } from 'src/services/cli-user-config';
26 import { CLI_EXPERIMENTAL_FEATURES } from 'src/constants';
@@ -80,23 +80,16 @@ const resolveParamsInput = (input: Option.Option<string>) =>
80 resolveOptionalTextInput(input, { missingValue: '{}' });
81
82 const parseCreateParams = (raw: string) =>
83 - Effect.gen(function* () {
84 - const parsed = yield* Effect.try({
85 - try: () => parseJsonIsh(raw),
86 - catch: () =>
83 + parseJsonRecord(raw).pipe(
84 + Either.mapLeft(
85 + error =>
86 new Error(
88 - "Invalid --params input. Provide JSON or a JS-style object literal, e.g. -p '{ trigger_config: { ... } }'."
89 - ),
90 - });
91 -
92 - if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
93 - return yield* Effect.fail(
94 - new Error("Expected --params to be an object, e.g. -p '{ trigger_config: { ... } }'.")
95 - );
96 - }
97 -
98 - return parsed as Record<string, unknown>;
99 - });
87 + error.reason === 'not-a-record'
88 + ? "Expected --params to be an object, e.g. -p '{ trigger_config: { ... } }'."
89 + : "Invalid --params input. Provide JSON or a JS-style object literal, e.g. -p '{ trigger_config: { ... } }'."
90 + )
91 + )
92 + );
93
94 const assertSupportedListenParams = (params: {
95 listeningToProjectEvent: boolean;
ts/packages/cli/src/commands/proxy.cmd.ts
+4 -9
@@ -1,5 +1,5 @@
1 import { Args, Command, Options } from '@effect/cli';
2 -import { Effect, Option } from 'effect';
2 +import { Effect, Either, Option } from 'effect';
3 import type {
4 SessionProxyExecuteParams,
5 SessionProxyExecuteResponse,
@@ -21,7 +21,7 @@ import {
21 ComposioNoActiveConnectionError,
22 mapComposioError,
23 } from 'src/services/composio-error-overrides';
24 -import { parseJsonIsh } from 'src/utils/parse-json-ish';
24 +import { parseJsonRecord } from 'src/utils/parse-json';
25
26 const endpoint = Args.text({ name: 'url' }).pipe(
27 Args.withDescription('Absolute or relative API endpoint to call through proxy execute.')
@@ -94,13 +94,8 @@ export const parseProxyHeader = (value: string): { name: string; value: string }
94
95 const resolveBodyInput = (input: Option.Option<string>) => resolveOptionalTextInput(input);
96
97 -export const parseProxyBody = (raw: string): unknown => {
98 - try {
99 - return parseJsonIsh(raw);
100 - } catch {
101 - return raw;
102 - }
103 -};
97 +export const parseProxyBody = (raw: string): unknown =>
98 + Either.getOrElse(parseJsonRecord(raw), (): unknown => raw);
99
100 const formatProxyOutput = (
101 result: Pick<SessionProxyExecuteResponse, 'status' | 'data' | 'headers' | 'binary_data'>
ts/packages/cli/src/commands/tools/commands/tools.execute.cmd.ts
+11 -17
@@ -5,7 +5,7 @@ import util from 'node:util';
5 import { Effect, Option, Either, Exit, Fiber, Cause } from 'effect';
6 import { encodingForModel } from 'js-tiktoken';
7 import { redact } from 'src/ui/redact';
8 -import { parseJsonIsh } from 'src/utils/parse-json-ish';
8 +import { parseJsonRecord } from 'src/utils/parse-json';
9 import { toolkitFromToolSlug } from 'src/utils/toolkit-from-tool-slug';
10 import { requireAuth } from 'src/effects/require-auth';
11 import { resolveOptionalTextInput } from 'src/effects/resolve-optional-text-input';
@@ -122,21 +122,16 @@ const resolveInput = (input: Option.Option<string>) =>
122 });
123
124 const parseArguments = (raw: string) =>
125 - Effect.gen(function* () {
126 - const parsed = yield* Effect.try({
127 - try: () => parseJsonIsh(raw),
128 - catch: () =>
125 + parseJsonRecord(raw).pipe(
126 + Either.mapLeft(
127 + error =>
128 new Error(
130 - 'Invalid JSON input. Provide JSON or a JS-style object literal, e.g. -d \'{ "key": "value" }\''
131 - ),
132 - });
133 - if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
134 - return yield* Effect.fail(
135 - new Error('Expected a JSON object for tool arguments, e.g. -d \'{ "key": "value" }\'')
136 - );
137 - }
138 - return parsed as Record<string, unknown>;
139 - });
129 + error.reason === 'not-a-record'
130 + ? 'Expected a JSON object for tool arguments, e.g. -d \'{ "key": "value" }\''
131 + : 'Invalid JSON input. Provide JSON or a JS-style object literal, e.g. -d \'{ "key": "value" }\''
132 + )
133 + )
134 + );
135
136 const hasNestedKey = (
137 record: Record<string, unknown>,
@@ -705,8 +700,7 @@ class ToolExecutionError extends Error {
700 }
701
702 type CachedValidationDecision =
708 - | { readonly status: 'valid' | 'stale' }
709 - | { readonly status: 'fail'; readonly error: unknown };
703 + { readonly status: 'valid' | 'stale' } | { readonly status: 'fail'; readonly error: unknown };
704
705 type ValidationState = {
706 readonly cacheHit: boolean;
ts/packages/cli/src/effect-errors/dependencies/fs/read-json/index.ts
+1 -1
@@ -1,2 +1,2 @@
1 -export * from './json-parsing.error';
1 +export { JsonParsingError } from 'src/utils/parse-json';
2 export * from './read-json';
ts/packages/cli/src/effect-errors/dependencies/fs/read-json/json-parsing.error.ts deleted
-6
@@ -1,6 +0,0 @@
1 -import { TaggedError } from 'effect/Data';
2 -
3 -export class JsonParsingError extends TaggedError('json-parsing-error')<{
4 - cause?: unknown;
5 - message?: string;
6 -}> {}
ts/packages/cli/src/effect-errors/dependencies/fs/read-json/parse-json.ts deleted
-21
@@ -1,21 +0,0 @@
1 -import { parse } from 'comment-json';
2 -import { Effect, pipe } from 'effect';
3 -
4 -import { JsonParsingError } from './json-parsing.error';
5 -
6 -export const parseJson = (data: string) =>
7 - pipe(
8 - Effect.sync(() => parse(data, null, true)),
9 - Effect.catchAll(e =>
10 - Effect.fail(
11 - new JsonParsingError({
12 - cause: e,
13 - })
14 - )
15 - ),
16 - Effect.withSpan('parse-json', {
17 - attributes: {
18 - data,
19 - },
20 - })
21 - );
ts/packages/cli/src/effect-errors/dependencies/fs/read-json/read-json.ts
+2 -2
@@ -1,7 +1,7 @@
1 import { FileSystem } from '@effect/platform/FileSystem';
2 import { Effect, pipe } from 'effect';
3
4 -import { parseJson } from './parse-json';
4 +import { parseJsonRecord } from 'src/utils/parse-json';
5
6 export const readJsonEffect = <TJson>(filePath: string) =>
7 pipe(
@@ -13,7 +13,7 @@ export const readJsonEffect = <TJson>(filePath: string) =>
13 return null;
14 }
15
16 - const json = yield* parseJson(data);
16 + const json = yield* parseJsonRecord(data);
17
18 return json as TJson;
19 }),
ts/packages/cli/src/utils/parse-json-ish.ts deleted
-13
@@ -1,13 +0,0 @@
1 -import { parse as parseJsonWithComments } from 'comment-json';
2 -
3 -export const parseJsonIsh = (raw: string): unknown => {
4 - try {
5 - return JSON.parse(raw) as unknown;
6 - } catch {
7 - try {
8 - return parseJsonWithComments(raw, undefined, true) as unknown;
9 - } catch {
10 - return Function(`"use strict"; return (${raw});`)() as unknown;
11 - }
12 - }
13 -};
ts/packages/cli/src/utils/parse-json.ts new
+41
@@ -0,0 +1,41 @@
1 +import { Data, Either, Predicate } from 'effect';
2 +import JSON5 from 'json5';
3 +
4 +export class JsonParsingError extends Data.TaggedError('JsonParsingError')<{
5 + /**
6 + * `syntax` — the input is not parseable at all;
7 + * `not-a-record` — valid JSON, but an array/scalar/null instead of an object.
8 + */
9 + reason: 'syntax' | 'not-a-record';
10 + cause: unknown;
11 +}> {}
12 +
13 +/**
14 + * Parses JSON or a JS-style object literal (unquoted keys, single quotes,
15 + * trailing commas, comments) into a record. JSON5 covers the documented
16 + * "JSON or JS-style object literal" contract without evaluating the input.
17 + * Inputs that parse to anything other than an object (arrays, scalars,
18 + * `null`) fail with `JsonParsingError`.
19 + *
20 + * Returns an `Either` because parsing is synchronous; `Either` is a subtype
21 + * of `Effect`, so call sites can `yield*` it or pipe it into Effect
22 + * combinators directly.
23 + */
24 +export const parseJsonRecord = (
25 + raw: string
26 +): Either.Either<Record<string, unknown>, JsonParsingError> =>
27 + Either.try({
28 + try: (): unknown => JSON5.parse(raw),
29 + catch: cause => new JsonParsingError({ reason: 'syntax', cause }),
30 + }).pipe(
31 + Either.filterOrLeft(
32 + Predicate.isRecord,
33 + parsed =>
34 + new JsonParsingError({
35 + reason: 'not-a-record',
36 + cause: new Error(
37 + `Expected a JSON object, received ${Array.isArray(parsed) ? 'an array' : typeof parsed}`
38 + ),
39 + })
40 + )
41 + );
ts/packages/cli/test/src/utils/parse-json.test.ts new
+65
@@ -0,0 +1,65 @@
1 +import { describe, expect, it } from '@effect/vitest';
2 +import { Either } from 'effect';
3 +import { JsonParsingError, parseJsonRecord } from 'src/utils/parse-json';
4 +
5 +const parse = (raw: string) => Either.getOrThrowWith(parseJsonRecord(raw), error => error);
6 +const parseError = (raw: string) => Either.flip(parseJsonRecord(raw)).pipe(Either.getOrNull);
7 +
8 +describe('parseJsonRecord', () => {
9 + it('parses strict JSON objects', () => {
10 + expect(parse('{"foo": "bar", "n": 1}')).toEqual({ foo: 'bar', n: 1 });
11 + });
12 +
13 + it('parses JS-style object literals (unquoted keys, single quotes, trailing commas)', () => {
14 + expect(parse("{ foo: 'bar', trailing: 1, }")).toEqual({ foo: 'bar', trailing: 1 });
15 + expect(parse("{ nested: { a: [1, 2,], b: 'c' } }")).toEqual({
16 + nested: { a: [1, 2], b: 'c' },
17 + });
18 + });
19 +
20 + it('parses JSON with comments', () => {
21 + expect(
22 + parse(`{
23 + // line comment
24 + "foo": "bar",
25 + /* block comment */
26 + "n": 1
27 + }`)
28 + ).toEqual({ foo: 'bar', n: 1 });
29 + });
30 +
31 + it('fails for JSON values that are not objects', () => {
32 + expect(parseError('[1, 2, 3]')).toBeInstanceOf(JsonParsingError);
33 + expect(parseError('"hello"')).toBeInstanceOf(JsonParsingError);
34 + expect(parseError('42')).toBeInstanceOf(JsonParsingError);
35 + expect(parseError('null')).toBeInstanceOf(JsonParsingError);
36 + });
37 +
38 + it('does not execute code embedded in the input', () => {
39 + const globals = globalThis as { __pwned?: boolean };
40 + delete globals.__pwned;
41 +
42 + expect(parseError('(globalThis.__pwned = true, {})')).toBeInstanceOf(JsonParsingError);
43 + expect(globals.__pwned).toBeUndefined();
44 +
45 + expect(parseError('process.exit(0)')).toBeInstanceOf(JsonParsingError);
46 + expect(parseError("require('node:child_process').execSync('true')")).toBeInstanceOf(
47 + JsonParsingError
48 + );
49 + expect(parseError('{ foo: (() => { globalThis.__pwned = true; })() }')).toBeInstanceOf(
50 + JsonParsingError
51 + );
52 + expect(globals.__pwned).toBeUndefined();
53 + });
54 +
55 + it('rejects plain JS expressions instead of evaluating them', () => {
56 + expect(parseError('1+1')).toBeInstanceOf(JsonParsingError);
57 + expect(parseError('[1, 2].map(x => x)')).toBeInstanceOf(JsonParsingError);
58 + expect(parseError('new Date()')).toBeInstanceOf(JsonParsingError);
59 + });
60 +
61 + it('fails for garbage input', () => {
62 + expect(parseError('not json at all!')).toBeInstanceOf(JsonParsingError);
63 + expect(parseError('')).toBeInstanceOf(JsonParsingError);
64 + });
65 +});