@composio/core 0.17.0 → 0.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{CustomTool-l-j5HtEf.mjs → CustomTool-Bz0f52QR.mjs} +16 -6
- package/dist/{CustomTool-Uip-fhPw.d.mts → CustomTool-VRfWzMix.d.mts} +1 -1
- package/dist/{FileModifierErrors-B8V8_3VE.mjs → FileModifierErrors-CwB-Inm9.mjs} +1 -1
- package/dist/FileToolModifier.utils.neutral-D_YkHwZP.mjs +188 -0
- package/dist/{SsrfErrors-DNJt57GL.mjs → SsrfErrors-xhdVE4yw.mjs} +123 -3
- package/dist/{Telemetry-DuGJSwUt.mjs → Telemetry-Dw9W5RSp.mjs} +28 -44
- package/dist/cancellation-P5YUlcfz.mjs +704 -0
- package/dist/{composio-B27X6i6A.d.mts → composio-Cb3d1jFe.d.mts} +250 -244
- package/dist/{customTool.types-B2Ava_j5.d.mts → customTool.types-B6ej_8XZ.d.mts} +146 -144
- package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +1 -1
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +4 -3
- package/dist/{errors-BcEUHZbq.mjs → errors-Ue9wMrPK.mjs} +5 -2
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/{fileUtils.node-B1Wn848p.mjs → fileUtils.node-KE5Fa-af.mjs} +7 -7
- package/dist/index.d.mts +108 -8
- package/dist/index.mjs +109 -55
- package/dist/models/Files.node.mjs +2 -2
- package/dist/{sensitiveFileUploadPaths-BVEt0peg.mjs → sensitiveFileUploadPaths-QN7w4n8v.mjs} +24 -7
- package/dist/ssrfGuard.node-BLX6b-Rf.mjs +384 -0
- package/dist/{types-DdZJuMm2.d.mts → types-CGdgK442.d.mts} +2 -2
- package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
- package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
- package/dist/utils/modifiers/FileToolModifier.node.mjs +59 -103
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
- package/dist/utils/modifiers/FileToolModifier.workerd.mjs +1 -1
- package/dist/utils/ssrfGuard.node.d.mts +14 -5
- package/dist/utils/ssrfGuard.node.mjs +1 -161
- package/dist/utils/ssrfGuard.workerd.d.mts +1 -1
- package/dist/utils/ssrfGuard.workerd.mjs +2 -2
- package/package.json +25 -3
- package/src/errors/ToolErrors.ts +1 -0
- package/src/errors/ValidationErrors.ts +2 -0
- package/src/index.ts +6 -0
- package/src/models/CustomTool.ts +41 -6
- package/src/models/RemoteFile.ts +54 -36
- package/src/models/ToolRouterSession.ts +45 -12
- package/src/models/Tools.ts +102 -39
- package/src/models/Triggers.ts +15 -0
- package/src/services/telemetry/TelemetryService.ts +27 -12
- package/src/telemetry/redact.ts +133 -6
- package/src/utils/fileUtils.node.ts +10 -2
- package/src/utils/jsonSchema.ts +505 -27
- package/src/utils/logger.ts +6 -6
- package/src/utils/modifiers/FileToolModifier.node.ts +85 -181
- package/src/utils/modifiers/FileToolModifier.utils.neutral.ts +199 -0
- package/src/utils/pinnedDispatcher.node.ts +214 -0
- package/src/utils/sdk.ts +1 -1
- package/src/utils/sensitiveFileUploadPaths.ts +36 -9
- package/src/utils/ssrfGuard.node.ts +101 -11
- package/src/utils/ssrfGuard.workerd.ts +5 -1
- package/dist/FileToolModifier.utils.neutral-B5rT711M.mjs +0 -72
- package/dist/cancellation-NVtGf3St.mjs +0 -364
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as ValidationError } from "./errors-
|
|
1
|
+
import { _ as ValidationError } from "./errors-Ue9wMrPK.mjs";
|
|
2
2
|
import { z as z$1 } from "zod/v3";
|
|
3
3
|
import * as z4 from "zod/v4";
|
|
4
4
|
import * as zodToJsonSchema from "zod-to-json-schema";
|
|
@@ -375,26 +375,32 @@ function buildCustomToolsMapFromResponse(tools, toolkits, experimental) {
|
|
|
375
375
|
};
|
|
376
376
|
for (const handle of tools) registerHandle(handle, handle.extendsToolkit);
|
|
377
377
|
if (toolkits) for (const tk of toolkits) for (const handle of tk.tools) registerHandle(handle, tk.slug);
|
|
378
|
-
const findHandle = (originalSlug, toolkit) => {
|
|
378
|
+
const findHandle = (finalSlug, originalSlug, toolkit) => {
|
|
379
379
|
const originalSlugKey = originalSlug.toUpperCase();
|
|
380
380
|
const qualifiedMatch = handlesByQualifiedOriginalSlug.get(qualifiedOriginalSlugKey(toolkit, originalSlugKey));
|
|
381
381
|
if (qualifiedMatch) return qualifiedMatch;
|
|
382
382
|
const bareMatches = handlesByOriginalSlug.get(originalSlugKey) ?? [];
|
|
383
|
-
|
|
383
|
+
if (bareMatches.length === 0) return void 0;
|
|
384
|
+
if (toolkit === void 0 && bareMatches.length === 1) return bareMatches[0];
|
|
385
|
+
const registered = [...new Set(bareMatches.map((m) => (m.toolkit ?? "custom").toUpperCase()))].sort();
|
|
386
|
+
throw new ValidationError(`Cannot map custom tool "${finalSlug}": original slug "${originalSlug}" for toolkit "${toolkit ?? "custom"}" has no exact local match. Registered for toolkits: ${registered.join(", ")}.`);
|
|
384
387
|
};
|
|
385
388
|
const addEntry = (finalSlug, originalSlug, toolkit) => {
|
|
386
389
|
const resolvedToolkit = toolkit ?? void 0;
|
|
387
|
-
const match = findHandle(originalSlug, resolvedToolkit);
|
|
390
|
+
const match = findHandle(finalSlug, originalSlug, resolvedToolkit);
|
|
388
391
|
if (!match) return;
|
|
389
392
|
const finalSlugKey = finalSlug.toUpperCase();
|
|
390
393
|
if (byFinalSlug.has(finalSlugKey)) throw new ValidationError(`Custom tool slug collision: "${finalSlug}" is already registered.`);
|
|
394
|
+
const entryToolkit = resolvedToolkit ?? match.toolkit;
|
|
395
|
+
const qualifiedKey = qualifiedOriginalSlugKey(entryToolkit, originalSlug);
|
|
396
|
+
if (byToolkitAndOriginalSlug.has(qualifiedKey)) throw new ValidationError(`Custom tool slug collision: original slug "${match.handle.slug}" is already registered for toolkit "${entryToolkit ?? "custom"}".`);
|
|
391
397
|
const entry = {
|
|
392
398
|
handle: match.handle,
|
|
393
399
|
finalSlug,
|
|
394
|
-
toolkit:
|
|
400
|
+
toolkit: entryToolkit
|
|
395
401
|
};
|
|
396
402
|
byFinalSlug.set(finalSlugKey, entry);
|
|
397
|
-
byToolkitAndOriginalSlug.set(
|
|
403
|
+
byToolkitAndOriginalSlug.set(qualifiedKey, entry);
|
|
398
404
|
addOriginalSlugAlias({
|
|
399
405
|
byOriginalSlug,
|
|
400
406
|
ambiguousOriginalSlugs,
|
|
@@ -404,6 +410,10 @@ function buildCustomToolsMapFromResponse(tools, toolkits, experimental) {
|
|
|
404
410
|
};
|
|
405
411
|
if (experimental?.custom_tools) for (const ct of experimental.custom_tools) addEntry(ct.slug, ct.original_slug, ct.extends_toolkit);
|
|
406
412
|
if (experimental?.custom_toolkits) for (const ctk of experimental.custom_toolkits) for (const ct of ctk.tools) addEntry(ct.slug, ct.original_slug, ctk.slug);
|
|
413
|
+
for (const [originalSlugKey, matches] of handlesByOriginalSlug) if (matches.length > 1) {
|
|
414
|
+
byOriginalSlug.delete(originalSlugKey);
|
|
415
|
+
ambiguousOriginalSlugs.add(originalSlugKey);
|
|
416
|
+
}
|
|
407
417
|
return {
|
|
408
418
|
byFinalSlug,
|
|
409
419
|
byOriginalSlug,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as CreateCustomToolkitParams, f as CustomToolkit, o as CustomTool, r as CreateCustomToolParams, t as AnyZodSchema } from "./customTool.types-
|
|
1
|
+
import { a as CreateCustomToolkitParams, f as CustomToolkit, o as CustomTool, r as CreateCustomToolParams, t as AnyZodSchema } from "./customTool.types-B6ej_8XZ.mjs";
|
|
2
2
|
import { SessionCreateResponse } from "@composio/client/resources/tool-router/session/session.mjs";
|
|
3
3
|
//#region src/models/CustomTool.d.ts
|
|
4
4
|
/**
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
//#region src/utils/modifiers/FileToolModifier.utils.neutral.ts
|
|
2
|
+
function isPlainObject(val) {
|
|
3
|
+
return typeof val === "object" && val !== null && !Array.isArray(val);
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Transforms a single JSON schema property, recursively handling nested properties,
|
|
7
|
+
* anyOf, oneOf, and allOf.
|
|
8
|
+
*/
|
|
9
|
+
const transformSchema = (property) => {
|
|
10
|
+
if (property.file_uploadable) return {
|
|
11
|
+
title: property.title,
|
|
12
|
+
description: property.description,
|
|
13
|
+
format: "path",
|
|
14
|
+
type: "string",
|
|
15
|
+
file_uploadable: true
|
|
16
|
+
};
|
|
17
|
+
const newProperty = { ...property };
|
|
18
|
+
if (property.type === "object" && property.properties) newProperty.properties = transformProperties(property.properties);
|
|
19
|
+
if (property.anyOf) newProperty.anyOf = property.anyOf.map(transformSchema);
|
|
20
|
+
if (property.oneOf) newProperty.oneOf = property.oneOf.map(transformSchema);
|
|
21
|
+
if (property.allOf) newProperty.allOf = property.allOf.map(transformSchema);
|
|
22
|
+
if (property.items) if (Array.isArray(property.items)) newProperty.items = property.items.map(transformSchema);
|
|
23
|
+
else newProperty.items = transformSchema(property.items);
|
|
24
|
+
return newProperty;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Transforms the properties of the tool schema to include the file upload URL.
|
|
28
|
+
*
|
|
29
|
+
* Attaches the format: 'path' to the properties that are file uploadable for agents.
|
|
30
|
+
*
|
|
31
|
+
* @param properties - The properties of the tool schema.
|
|
32
|
+
* @returns The transformed properties.
|
|
33
|
+
*/
|
|
34
|
+
const transformProperties = (properties) => {
|
|
35
|
+
const newProperties = {};
|
|
36
|
+
for (const [key, property] of Object.entries(properties)) newProperties[key] = transformSchema(property);
|
|
37
|
+
return newProperties;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Recursively checks if a schema (or any of its variants) contains a specific file property.
|
|
41
|
+
*/
|
|
42
|
+
const schemaHasFileProperty = (schema, property) => {
|
|
43
|
+
if (!schema) return false;
|
|
44
|
+
if (schema[property]) return true;
|
|
45
|
+
if (schema.properties) {
|
|
46
|
+
for (const prop of Object.values(schema.properties)) if (schemaHasFileProperty(prop, property)) return true;
|
|
47
|
+
}
|
|
48
|
+
if (schema.anyOf) {
|
|
49
|
+
for (const variant of schema.anyOf) if (schemaHasFileProperty(variant, property)) return true;
|
|
50
|
+
}
|
|
51
|
+
if (schema.oneOf) {
|
|
52
|
+
for (const variant of schema.oneOf) if (schemaHasFileProperty(variant, property)) return true;
|
|
53
|
+
}
|
|
54
|
+
if (schema.allOf) {
|
|
55
|
+
for (const variant of schema.allOf) if (schemaHasFileProperty(variant, property)) return true;
|
|
56
|
+
}
|
|
57
|
+
if (schema.items) {
|
|
58
|
+
if (Array.isArray(schema.items)) {
|
|
59
|
+
for (const item of schema.items) if (schemaHasFileProperty(item, property)) return true;
|
|
60
|
+
} else if (schemaHasFileProperty(schema.items, property)) return true;
|
|
61
|
+
}
|
|
62
|
+
for (const definitions of [schema.$defs, schema.definitions]) {
|
|
63
|
+
if (!definitions) continue;
|
|
64
|
+
for (const definition of Object.values(definitions)) if (schemaHasFileProperty(definition, property)) return true;
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Recursively checks if a schema (or any of its variants) contains file_uploadable properties.
|
|
70
|
+
*/
|
|
71
|
+
const schemaHasFileUploadable = (schema) => {
|
|
72
|
+
return schemaHasFileProperty(schema, "file_uploadable");
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Sentinel a leaf handler returns to have {@link walkFileUploadableLeaves}
|
|
76
|
+
* omit that key/item from its parent container. `''` and `null` are legal
|
|
77
|
+
* payload values, so neither can double as "remove this".
|
|
78
|
+
*/
|
|
79
|
+
const DELETE_VALUE = Symbol("composio.delete-value");
|
|
80
|
+
/**
|
|
81
|
+
* `''` at a `file_uploadable` leaf means "no file": it is never a staged
|
|
82
|
+
* `{ name, mimetype, s3key }` descriptor, so the backend rejects it with a
|
|
83
|
+
* validation error, while callers (and the playground UI) mean "absent". The
|
|
84
|
+
* walker omits the key instead. `null` is left alone — schemas with a `null`
|
|
85
|
+
* variant accept it, and the backend reports the mismatch otherwise.
|
|
86
|
+
*/
|
|
87
|
+
const isEmptyFileValue = (value) => value === "";
|
|
88
|
+
const getSchemaVariants = (schema) => [
|
|
89
|
+
...schema?.anyOf ?? [],
|
|
90
|
+
...schema?.oneOf ?? [],
|
|
91
|
+
...schema?.allOf ?? []
|
|
92
|
+
];
|
|
93
|
+
/** Best-effort runtime shape match for selecting composed schema variants. */
|
|
94
|
+
const jsonSchemaTypeMatchesValue = (schema, value) => {
|
|
95
|
+
const schemaType = schema.type;
|
|
96
|
+
if (Array.isArray(schemaType)) return schemaType.some((type) => jsonSchemaTypeMatchesValue({
|
|
97
|
+
...schema,
|
|
98
|
+
type
|
|
99
|
+
}, value));
|
|
100
|
+
if (schemaType === void 0) {
|
|
101
|
+
if (schema.properties) return isPlainObject(value);
|
|
102
|
+
if (schema.items) return Array.isArray(value);
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
switch (schemaType) {
|
|
106
|
+
case "array": return Array.isArray(value);
|
|
107
|
+
case "object": return isPlainObject(value);
|
|
108
|
+
case "string": return typeof value === "string";
|
|
109
|
+
case "integer": return Number.isInteger(value);
|
|
110
|
+
case "number": return typeof value === "number";
|
|
111
|
+
case "boolean": return typeof value === "boolean";
|
|
112
|
+
case "null": return value === null;
|
|
113
|
+
default: return false;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
/** Mirrors the array-shape inference used by {@link jsonSchemaTypeMatchesValue}. */
|
|
117
|
+
const isArrayShapedSchema = (schema) => {
|
|
118
|
+
if (!schema) return false;
|
|
119
|
+
if (Array.isArray(schema.type)) return schema.type.includes("array");
|
|
120
|
+
return schema.type === "array" || schema.type === void 0 && schema.items !== void 0;
|
|
121
|
+
};
|
|
122
|
+
/** Mirrors the object-shape inference used by {@link jsonSchemaTypeMatchesValue}. */
|
|
123
|
+
const isObjectShapedSchema = (schema) => {
|
|
124
|
+
if (!schema) return false;
|
|
125
|
+
if (Array.isArray(schema.type)) return schema.type.includes("object");
|
|
126
|
+
return schema.type === "object" || schema.type === void 0 && schema.properties !== void 0;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Picks the file-bearing `anyOf`/`oneOf`/`allOf` variant whose JSON Schema
|
|
130
|
+
* shape matches the runtime value, falling back to the first file-bearing
|
|
131
|
+
* variant to preserve historical behavior.
|
|
132
|
+
*/
|
|
133
|
+
const findSchemaVariantWithFileProperty = (schema, property, value) => {
|
|
134
|
+
const candidates = getSchemaVariants(schema).filter((variant) => schemaHasFileProperty(variant, property));
|
|
135
|
+
return candidates.find((candidate) => jsonSchemaTypeMatchesValue(candidate, value)) ?? candidates[0];
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Recursively walks a runtime value alongside its (already dereferenced)
|
|
139
|
+
* JSON-Schema node and passes every value sitting at a `file_uploadable`
|
|
140
|
+
* node through `leaf`. A leaf returning {@link DELETE_VALUE} is omitted from
|
|
141
|
+
* its parent object/array. Returns a **new** value; nothing is mutated.
|
|
142
|
+
*
|
|
143
|
+
* Composed schemas are resolved to the single file-bearing variant whose
|
|
144
|
+
* shape matches the value: with `oneOf`, exactly one variant should apply at
|
|
145
|
+
* runtime, and applying several would stage the same file once per variant.
|
|
146
|
+
*/
|
|
147
|
+
const walkFileUploadableLeaves = async (value, schema, leaf) => {
|
|
148
|
+
if (schema?.file_uploadable) return leaf(value);
|
|
149
|
+
const uploadableVariant = findSchemaVariantWithFileProperty(schema, "file_uploadable", value);
|
|
150
|
+
if (uploadableVariant) {
|
|
151
|
+
const matchingNonFileVariant = getSchemaVariants(schema).some((variant) => !schemaHasFileProperty(variant, "file_uploadable") && jsonSchemaTypeMatchesValue(variant, value));
|
|
152
|
+
if (isEmptyFileValue(value) && isArrayShapedSchema(uploadableVariant) && !matchingNonFileVariant) return leaf(value);
|
|
153
|
+
return walkFileUploadableLeaves(value, uploadableVariant, leaf);
|
|
154
|
+
}
|
|
155
|
+
if (isEmptyFileValue(value) && isArrayShapedSchema(schema) && schemaHasFileProperty(schema, "file_uploadable")) return leaf(value);
|
|
156
|
+
if (isObjectShapedSchema(schema) && schema?.properties && isPlainObject(value)) {
|
|
157
|
+
const transformed = {};
|
|
158
|
+
for (const [k, v] of Object.entries(value)) {
|
|
159
|
+
const propertySchema = Object.hasOwn(schema.properties, k) ? schema.properties[k] : void 0;
|
|
160
|
+
const walked = await walkFileUploadableLeaves(v, propertySchema, leaf);
|
|
161
|
+
if (walked !== DELETE_VALUE) Object.defineProperty(transformed, k, {
|
|
162
|
+
configurable: true,
|
|
163
|
+
enumerable: true,
|
|
164
|
+
value: walked,
|
|
165
|
+
writable: true
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
return transformed;
|
|
169
|
+
}
|
|
170
|
+
if (isArrayShapedSchema(schema) && schema?.items && Array.isArray(value)) {
|
|
171
|
+
const itemSchema = Array.isArray(schema.items) ? schema.items[0] : schema.items;
|
|
172
|
+
return (await Promise.all(value.map((item) => walkFileUploadableLeaves(item, itemSchema, leaf)))).filter((item) => item !== DELETE_VALUE);
|
|
173
|
+
}
|
|
174
|
+
return value;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Omits `''` at `file_uploadable` leaves of `args` without uploading
|
|
178
|
+
* anything. This is the schema-aware half of the upload modifier that needs
|
|
179
|
+
* no filesystem access, so it also runs when automatic upload is disabled:
|
|
180
|
+
* an empty file value is never a valid staged descriptor and the backend
|
|
181
|
+
* would reject it (https://github.com/ComposioHQ/composio/issues/4233).
|
|
182
|
+
* Any other value — a local path, a staged descriptor, a list — is
|
|
183
|
+
* forwarded untouched.
|
|
184
|
+
*/
|
|
185
|
+
const dropEmptyFileUploads = (args, schema) => walkFileUploadableLeaves(args, schema, async (value) => isEmptyFileValue(value) ? DELETE_VALUE : value);
|
|
186
|
+
|
|
187
|
+
//#endregion
|
|
188
|
+
export { isEmptyFileValue as a, transformProperties as c, getSchemaVariants as i, walkFileUploadableLeaves as l, dropEmptyFileUploads as n, isPlainObject as o, findSchemaVariantWithFileProperty as r, schemaHasFileUploadable as s, DELETE_VALUE as t };
|
|
@@ -55,6 +55,125 @@ const COMPOSIO_LOG_LEVEL = getEnvVariable("COMPOSIO_LOG_LEVEL");
|
|
|
55
55
|
const IS_DEVELOPMENT_OR_CI = getEnvVariable("DEVELOPMENT") || getEnvVariable("CI") || false;
|
|
56
56
|
const DEFAULT_TOOL_ROUTER_SESSION_FILES_MOUNT_ID = "files";
|
|
57
57
|
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/telemetry/redact.ts
|
|
60
|
+
/**
|
|
61
|
+
* Best-effort redaction of secrets from free-form error text before it is sent
|
|
62
|
+
* to the telemetry endpoint.
|
|
63
|
+
*
|
|
64
|
+
* Error `message` and `stack` fields routinely interpolate URLs (with
|
|
65
|
+
* query-string tokens / presigned signatures), `Authorization` headers, API
|
|
66
|
+
* keys, and connected-account identifiers. None of that should leave the
|
|
67
|
+
* process. Structured telemetry fields never carry raw secrets, so only the two
|
|
68
|
+
* free-form strings are passed through here.
|
|
69
|
+
*
|
|
70
|
+
* This is defence-in-depth, not a proof: it targets the shapes we have seen
|
|
71
|
+
* leak. When in doubt it over-redacts rather than under-redacts.
|
|
72
|
+
*/
|
|
73
|
+
const REDACTED = "[REDACTED]";
|
|
74
|
+
const SECRET_KEY_PATTERN = String.raw`authorization|auth|api[-_]?key|apikey|x-api-key|access[-_]?token|refresh[-_]?token|client[-_]?secret|secret|password|passwd|pwd`;
|
|
75
|
+
const SECRET_KEY_WITH_PREFIX_PATTERN = String.raw`(?:[A-Za-z0-9]+_)*(?:${SECRET_KEY_PATTERN})`;
|
|
76
|
+
const QUOTED_SECRET_KEY_PREFIX = String.raw`(["'])(${SECRET_KEY_WITH_PREFIX_PATTERN})\1(\s*[:=]+\s*)`;
|
|
77
|
+
const BARE_SECRET_KEY_PREFIX = String.raw`(?<![A-Za-z0-9"'])(${SECRET_KEY_PATTERN})\b(\s*[:=]+\s*)`;
|
|
78
|
+
const ESCAPED_SECRET_KEY_PREFIX = String.raw`(?<![A-Za-z0-9])(${SECRET_KEY_PATTERN})\b((?:\\["'])?\s*[:=]+\s*)`;
|
|
79
|
+
const SECRET_PAIR_PREFIX = String.raw`(?<![A-Za-z0-9])(${SECRET_KEY_PATTERN})\b(["']?\s*[:=]+\s*)`;
|
|
80
|
+
const BARE_KEY_DOUBLE_QUOTED_VALUE = new RegExp(String.raw`${BARE_SECRET_KEY_PREFIX}"((?:\\.|[^"\\\r\n])*)"`, "gi");
|
|
81
|
+
const BARE_KEY_SINGLE_QUOTED_VALUE = new RegExp(String.raw`${BARE_SECRET_KEY_PREFIX}'((?:\\.|[^'\\\r\n])*)'`, "gi");
|
|
82
|
+
const BARE_KEY_ESCAPED_DOUBLE_QUOTED_VALUE = new RegExp(String.raw`${ESCAPED_SECRET_KEY_PREFIX}\\"((?:\\.|[^"\\\r\n])*)\\"`, "gi");
|
|
83
|
+
const BARE_KEY_ESCAPED_SINGLE_QUOTED_VALUE = new RegExp(String.raw`${ESCAPED_SECRET_KEY_PREFIX}\\'((?:\\.|[^'\\\r\n])*)\\'`, "gi");
|
|
84
|
+
const SECRET_PAIR_UNQUOTED = new RegExp(String.raw`${SECRET_PAIR_PREFIX}(?!\\["'])([^\s"',}&]+)`, "gi");
|
|
85
|
+
const CONTAINS_QUOTED_FIELD = /(?:^|[,{\s])(["'])[^"'\\\r\n]+\1\s*[:=]\s*$/;
|
|
86
|
+
const REDACTION_RULES = [
|
|
87
|
+
[/(\bhttps?:\/\/[^\s?#'"]+)\?[^\s'"]*/gi, `$1?${REDACTED}`],
|
|
88
|
+
[/\b(bearer|basic)\s+[A-Za-z0-9._~+/=-]+/gi, `$1 ${REDACTED}`],
|
|
89
|
+
[new RegExp(String.raw`${QUOTED_SECRET_KEY_PREFIX}"(?:\\.|[^"\\\r\n])*"`, "gi"), `$1$2$1$3"${REDACTED}"`],
|
|
90
|
+
[new RegExp(String.raw`${QUOTED_SECRET_KEY_PREFIX}'(?:\\.|[^'\\\r\n])*'`, "gi"), `$1$2$1$3'${REDACTED}'`]
|
|
91
|
+
];
|
|
92
|
+
const isWordCharacter = (character) => /[\p{L}\p{N}_]/u.test(character);
|
|
93
|
+
const activeQuotesAt = (input, offsets) => {
|
|
94
|
+
const activeQuotes = /* @__PURE__ */ new Map();
|
|
95
|
+
let quote;
|
|
96
|
+
let escaped = false;
|
|
97
|
+
let lastOffset = -1;
|
|
98
|
+
for (const offset of offsets) lastOffset = Math.max(lastOffset, offset);
|
|
99
|
+
for (let position = 0; position < input.length; position += 1) {
|
|
100
|
+
const character = input[position];
|
|
101
|
+
if (offsets.has(position)) {
|
|
102
|
+
activeQuotes.set(position, quote);
|
|
103
|
+
if (position === lastOffset) break;
|
|
104
|
+
}
|
|
105
|
+
if (character === "\n" || character === "\r") {
|
|
106
|
+
quote = void 0;
|
|
107
|
+
escaped = false;
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
const previous = position > 0 && !["\n", "\r"].includes(input[position - 1]) ? input[position - 1] : "";
|
|
111
|
+
const following = input[position + 1] ?? "";
|
|
112
|
+
if (!quote) {
|
|
113
|
+
if (character === "\"" || character === "'" && !isWordCharacter(previous)) quote = character;
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (escaped) escaped = false;
|
|
117
|
+
else if (character === "\\") escaped = true;
|
|
118
|
+
else if (character === quote) {
|
|
119
|
+
if (quote === "'" && isWordCharacter(previous) && isWordCharacter(following)) continue;
|
|
120
|
+
quote = void 0;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return activeQuotes;
|
|
124
|
+
};
|
|
125
|
+
const completesQuotedFieldAt = (input, index, quote) => {
|
|
126
|
+
let escaped = false;
|
|
127
|
+
for (let position = index; position < input.length; position += 1) {
|
|
128
|
+
const character = input[position];
|
|
129
|
+
if (character === "\n" || character === "\r") return false;
|
|
130
|
+
if (escaped) {
|
|
131
|
+
escaped = false;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (character === "\\") {
|
|
135
|
+
escaped = true;
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (character !== quote) continue;
|
|
139
|
+
let separator = position + 1;
|
|
140
|
+
while (separator < input.length && /\s/.test(input[separator])) separator += 1;
|
|
141
|
+
return input[separator] === ":" || input[separator] === "=";
|
|
142
|
+
}
|
|
143
|
+
return false;
|
|
144
|
+
};
|
|
145
|
+
const redactBareQuotedValue = (input, pattern, quote) => {
|
|
146
|
+
pattern.lastIndex = 0;
|
|
147
|
+
const matches = Array.from(input.matchAll(pattern));
|
|
148
|
+
if (matches.length === 0) return input;
|
|
149
|
+
const activeQuotes = activeQuotesAt(input, new Set(matches.map((match) => match.index)));
|
|
150
|
+
const parts = [];
|
|
151
|
+
let cursor = 0;
|
|
152
|
+
for (const match of matches) {
|
|
153
|
+
const offset = match.index;
|
|
154
|
+
parts.push(input.slice(cursor, offset));
|
|
155
|
+
if (activeQuotes.get(offset) === quote && (completesQuotedFieldAt(input, offset + match[0].length, quote) || CONTAINS_QUOTED_FIELD.test(match[3]))) parts.push(match[0]);
|
|
156
|
+
else parts.push(`${match[1]}${match[2]}${quote}${REDACTED}${quote}`);
|
|
157
|
+
cursor = offset + match[0].length;
|
|
158
|
+
}
|
|
159
|
+
parts.push(input.slice(cursor));
|
|
160
|
+
return parts.join("");
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* Redact common secret shapes from a free-form string. Returns the input
|
|
164
|
+
* unchanged when it is empty or `undefined`.
|
|
165
|
+
*/
|
|
166
|
+
const redactSensitiveText = (input) => {
|
|
167
|
+
if (!input) return input;
|
|
168
|
+
let output = input;
|
|
169
|
+
for (const [pattern, replacement] of REDACTION_RULES) output = output.replace(pattern, replacement);
|
|
170
|
+
output = output.replace(BARE_KEY_ESCAPED_DOUBLE_QUOTED_VALUE, `$1$2\\"${REDACTED}\\"`);
|
|
171
|
+
output = output.replace(BARE_KEY_ESCAPED_SINGLE_QUOTED_VALUE, `$1$2\\'${REDACTED}\\'`);
|
|
172
|
+
output = redactBareQuotedValue(output, BARE_KEY_DOUBLE_QUOTED_VALUE, "\"");
|
|
173
|
+
output = redactBareQuotedValue(output, BARE_KEY_SINGLE_QUOTED_VALUE, "'");
|
|
174
|
+
return output.replace(SECRET_PAIR_UNQUOTED, `$1$2${REDACTED}`);
|
|
175
|
+
};
|
|
176
|
+
|
|
58
177
|
//#endregion
|
|
59
178
|
//#region src/utils/logger.ts
|
|
60
179
|
const LOG_LEVELS = {
|
|
@@ -91,9 +210,10 @@ var Logger = class {
|
|
|
91
210
|
return String(arg);
|
|
92
211
|
}
|
|
93
212
|
}).join("\n");
|
|
94
|
-
|
|
213
|
+
const redactedArgs = redactSensitiveText(formattedArgs) ?? formattedArgs;
|
|
214
|
+
if (!this.includeTimestamp) return redactedArgs;
|
|
95
215
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
96
|
-
return `${pc.gray(timestamp)} - ${
|
|
216
|
+
return `${pc.gray(timestamp)} - ${redactedArgs}`;
|
|
97
217
|
}
|
|
98
218
|
shouldLog(level) {
|
|
99
219
|
return LOG_LEVELS[level] <= LOG_LEVELS[this.level];
|
|
@@ -381,4 +501,4 @@ var ComposioBlockedInternalUrlError = class extends ComposioError$1 {
|
|
|
381
501
|
};
|
|
382
502
|
|
|
383
503
|
//#endregion
|
|
384
|
-
export {
|
|
504
|
+
export { redactSensitiveText as a, DEFAULT_BASE_URL as c, TEMP_FILES_DIRECTORY_NAME as d, USER_DATA_FILE_NAME as f, getEnvsWithPrefix as h, logger as i, DEFAULT_TOOL_ROUTER_SESSION_FILES_MOUNT_ID as l, getEnvVariable as m, SsrfErrorCodes as n, COMPOSIO_DIR as o, constants_exports as p, ComposioError$1 as r, COMPOSIO_LOG_LEVEL as s, ComposioBlockedInternalUrlError as t, IS_DEVELOPMENT_OR_CI as u };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as logger,
|
|
2
|
-
import { l as getRandomUUID } from "./sensitiveFileUploadPaths-
|
|
1
|
+
import { a as redactSensitiveText, i as logger, m as getEnvVariable, r as ComposioError$1 } from "./SsrfErrors-xhdVE4yw.mjs";
|
|
2
|
+
import { l as getRandomUUID } from "./sensitiveFileUploadPaths-QN7w4n8v.mjs";
|
|
3
3
|
import { ComposioError } from "@composio/client";
|
|
4
4
|
|
|
5
5
|
//#region src/types/telemetry.types.ts
|
|
@@ -64,7 +64,31 @@ var BatchProcessor = class {
|
|
|
64
64
|
//#endregion
|
|
65
65
|
//#region src/services/telemetry/TelemetryService.ts
|
|
66
66
|
const TELEMETRY_URL = "https://telemetry.composio.dev/v1";
|
|
67
|
+
const TELEMETRY_TIMEOUT_MS = 3e3;
|
|
67
68
|
var TelemetryService = class {
|
|
69
|
+
/**
|
|
70
|
+
* POSTs a best-effort telemetry payload, bounding the request so a stalled
|
|
71
|
+
* endpoint cannot leave it pending indefinitely.
|
|
72
|
+
*
|
|
73
|
+
* A hand-rolled timer rather than AbortSignal.timeout so it can be cleared the
|
|
74
|
+
* moment the response lands: an uncleared timer is itself pending work, which on
|
|
75
|
+
* workerd pins the request context open for the full timeout on every successful
|
|
76
|
+
* send. Mirrors the bound applied to the npm version check.
|
|
77
|
+
*/
|
|
78
|
+
static async postWithTimeout(url, payload) {
|
|
79
|
+
const controller = new AbortController();
|
|
80
|
+
const timer = setTimeout(() => controller.abort(), TELEMETRY_TIMEOUT_MS);
|
|
81
|
+
try {
|
|
82
|
+
return await fetch(url, {
|
|
83
|
+
method: "POST",
|
|
84
|
+
headers: { "Content-Type": "application/json" },
|
|
85
|
+
body: JSON.stringify(payload),
|
|
86
|
+
signal: controller.signal
|
|
87
|
+
});
|
|
88
|
+
} finally {
|
|
89
|
+
clearTimeout(timer);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
68
92
|
/**
|
|
69
93
|
* Sends a metric to the Telemetry API.
|
|
70
94
|
* @param payload - The payload to send to the Telemetry API.
|
|
@@ -72,11 +96,7 @@ var TelemetryService = class {
|
|
|
72
96
|
*/
|
|
73
97
|
static async sendMetric(payload) {
|
|
74
98
|
try {
|
|
75
|
-
return await
|
|
76
|
-
method: "POST",
|
|
77
|
-
headers: { "Content-Type": "application/json" },
|
|
78
|
-
body: JSON.stringify(payload)
|
|
79
|
-
});
|
|
99
|
+
return await this.postWithTimeout(`${TELEMETRY_URL}/metrics/invocations`, payload);
|
|
80
100
|
} catch (error) {
|
|
81
101
|
logger.debug("Error sending metric telemetry", error);
|
|
82
102
|
}
|
|
@@ -88,49 +108,13 @@ var TelemetryService = class {
|
|
|
88
108
|
*/
|
|
89
109
|
static async sendErrorLog(payload) {
|
|
90
110
|
try {
|
|
91
|
-
return await
|
|
92
|
-
method: "POST",
|
|
93
|
-
headers: { "Content-Type": "application/json" },
|
|
94
|
-
body: JSON.stringify(payload)
|
|
95
|
-
});
|
|
111
|
+
return await this.postWithTimeout(`${TELEMETRY_URL}/errors`, payload);
|
|
96
112
|
} catch (error) {
|
|
97
113
|
logger.debug("Error sending error telemetry", error);
|
|
98
114
|
}
|
|
99
115
|
}
|
|
100
116
|
};
|
|
101
117
|
|
|
102
|
-
//#endregion
|
|
103
|
-
//#region src/telemetry/redact.ts
|
|
104
|
-
/**
|
|
105
|
-
* Best-effort redaction of secrets from free-form error text before it is sent
|
|
106
|
-
* to the telemetry endpoint.
|
|
107
|
-
*
|
|
108
|
-
* Error `message` and `stack` fields routinely interpolate URLs (with
|
|
109
|
-
* query-string tokens / presigned signatures), `Authorization` headers, API
|
|
110
|
-
* keys, and connected-account identifiers. None of that should leave the
|
|
111
|
-
* process. Structured telemetry fields never carry raw secrets, so only the two
|
|
112
|
-
* free-form strings are passed through here.
|
|
113
|
-
*
|
|
114
|
-
* This is defence-in-depth, not a proof: it targets the shapes we have seen
|
|
115
|
-
* leak. When in doubt it over-redacts rather than under-redacts.
|
|
116
|
-
*/
|
|
117
|
-
const REDACTED = "[REDACTED]";
|
|
118
|
-
const REDACTION_RULES = [
|
|
119
|
-
[/(\bhttps?:\/\/[^\s?#'"]+)\?[^\s'"]*/gi, `$1?${REDACTED}`],
|
|
120
|
-
[/\b(bearer|basic)\s+[A-Za-z0-9._~+/=-]+/gi, `$1 ${REDACTED}`],
|
|
121
|
-
[/(?<![A-Za-z0-9])(authorization|api[-_]?key|apikey|x-api-key|access[-_]?token|refresh[-_]?token|client[-_]?secret|secret|password|passwd|pwd)\b(["']?\s*[:=]+\s*)(["']?)([^\s"',}&]+)\3/gi, `$1$2$3${REDACTED}$3`]
|
|
122
|
-
];
|
|
123
|
-
/**
|
|
124
|
-
* Redact common secret shapes from a free-form string. Returns the input
|
|
125
|
-
* unchanged when it is empty or `undefined`.
|
|
126
|
-
*/
|
|
127
|
-
const redactSensitiveText = (input) => {
|
|
128
|
-
if (!input) return input;
|
|
129
|
-
let output = input;
|
|
130
|
-
for (const [pattern, replacement] of REDACTION_RULES) output = output.replace(pattern, replacement);
|
|
131
|
-
return output;
|
|
132
|
-
};
|
|
133
|
-
|
|
134
118
|
//#endregion
|
|
135
119
|
//#region src/telemetry/Telemetry.ts
|
|
136
120
|
/**
|