@composio/core 0.13.1 → 0.14.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/README.md +62 -247
- package/dist/BaseProvider-Dc5yKZhk.d.mts +29394 -0
- package/dist/{CustomTool-DLf7JeKt.d.mts → CustomTool-4nVuwLzO.d.mts} +1 -2
- package/dist/{CustomTool-D9qwyMrv.mjs → CustomTool-l-j5HtEf.mjs} +17 -15
- package/dist/FileModifierErrors-B8V8_3VE.mjs +97 -0
- package/dist/{FileModifierErrors-3fSwIWoa.mjs → SsrfErrors-DNJt57GL.mjs} +24 -85
- package/dist/{Telemetry-DhGI_J4G.mjs → Telemetry-CF0rNHu2.mjs} +40 -8
- package/dist/{jsonSchema-CFKdONpP.mjs → cancellation-BbJ-UQ__.mjs} +64 -19
- package/dist/{composio-BHSQwOUz.d.mts → composio-ChU3eD9F.d.mts} +1083 -1061
- package/dist/{customTool.types-9yFqPjdw.d.mts → customTool.types-CX2-LbfI.d.mts} +634 -601
- package/dist/docs/reference/sdk-reference/typescript/index.mdx +1 -22
- package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +2 -0
- package/dist/{errors-DSIlYfl5.mjs → errors-BcEUHZbq.mjs} +75 -74
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/{fileUtils.node-BiO1JQsJ.mjs → fileUtils.node-DOkW4PBg.mjs} +36 -70
- package/dist/index.d.mts +2446 -1563
- package/dist/index.mjs +1415 -1381
- package/dist/models/Files.node.d.mts +2 -11
- package/dist/models/Files.node.mjs +2 -2
- package/dist/models/Files.workerd.d.mts +0 -1
- package/dist/platform/node.d.mts +1 -2
- package/dist/platform/node.mjs +3 -0
- package/dist/platform/workerd.d.mts +1 -2
- package/dist/platform/workerd.mjs +30 -3
- package/dist/sensitiveFileUploadPaths-C43dHP7S.mjs +164 -0
- package/dist/{types-BJLCRj9q.d.mts → types-D5N60gUD.d.mts} +2 -3
- package/dist/{types-DdoCRzLj.d.mts → types-DY1r-kN9.d.mts} +9 -0
- package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -2
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -2
- package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -2
- package/dist/utils/modifiers/FileToolModifier.node.mjs +6 -5
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -2
- package/dist/utils/ssrfGuard.node.d.mts +22 -0
- package/dist/utils/ssrfGuard.node.mjs +152 -0
- package/dist/utils/ssrfGuard.workerd.d.mts +9 -0
- package/dist/utils/ssrfGuard.workerd.mjs +17 -0
- package/package.json +20 -15
- package/src/errors/SsrfErrors.ts +48 -0
- package/src/errors/index.ts +3 -0
- package/src/index.ts +10 -0
- package/src/models/CustomTool.ts +1 -3
- package/src/models/ToolRouterSession.ts +38 -16
- package/src/models/ToolRouterSessionFileMount.ts +7 -3
- package/src/models/Tools.ts +32 -2
- package/src/models/Triggers.ts +16 -76
- package/src/platform/node.ts +4 -0
- package/src/platform/types.ts +10 -0
- package/src/platform/workerd.ts +36 -3
- package/src/provider/OpenAIProvider.ts +19 -14
- package/src/telemetry/Telemetry.ts +9 -6
- package/src/telemetry/redact.ts +40 -0
- package/src/types/tool.types.ts +36 -32
- package/src/utils/fileUtils.node.ts +29 -6
- package/src/utils/jsonSchema.ts +58 -0
- package/src/utils/modifiers/FileToolModifier.node.ts +2 -1
- package/src/utils/readResponseBody.ts +63 -0
- package/src/utils/sdk.ts +5 -4
- package/src/utils/{sensitiveFileUploadPaths.node.ts → sensitiveFileUploadPaths.ts} +29 -13
- package/src/utils/ssrfGuard.node.ts +202 -0
- package/src/utils/ssrfGuard.workerd.ts +19 -0
- package/src/utils/toolkitVersion.ts +21 -2
- package/dist/BaseProvider-Brb3o86-.d.mts +0 -29425
- package/dist/CustomTool-NpHpqdnU.d.mts +0 -74
- package/dist/buffer-PcbMMsgm.mjs +0 -33
- package/dist/composio-DfPD7BAi.d.mts +0 -5666
- package/dist/customTool.types-D-6YqFdW.d.mts +0 -2826
- package/dist/types-CCh8qvui.d.mts +0 -12
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { n as FileUploadData, t as FileDownloadData } from "../files.types-DeMC_mAW.mjs";
|
|
2
2
|
import ComposioClient from "@composio/client";
|
|
3
|
-
|
|
4
3
|
//#region src/models/Files.node.d.ts
|
|
5
4
|
declare class Files {
|
|
6
5
|
private readonly client;
|
|
@@ -27,11 +26,7 @@ declare class Files {
|
|
|
27
26
|
* toolkitSlug: 'google_drive'
|
|
28
27
|
* });
|
|
29
28
|
* */
|
|
30
|
-
upload({
|
|
31
|
-
file,
|
|
32
|
-
toolSlug,
|
|
33
|
-
toolkitSlug
|
|
34
|
-
}: {
|
|
29
|
+
upload({ file, toolSlug, toolkitSlug }: {
|
|
35
30
|
file: File | string;
|
|
36
31
|
toolSlug: string;
|
|
37
32
|
toolkitSlug: string;
|
|
@@ -41,11 +36,7 @@ declare class Files {
|
|
|
41
36
|
* @param s3key - The S3 key of the file to download.
|
|
42
37
|
* @returns The file data.
|
|
43
38
|
*/
|
|
44
|
-
download({
|
|
45
|
-
toolSlug,
|
|
46
|
-
s3Url,
|
|
47
|
-
mimeType
|
|
48
|
-
}: {
|
|
39
|
+
download({ toolSlug, s3Url, mimeType }: {
|
|
49
40
|
s3Url: string;
|
|
50
41
|
toolSlug: string;
|
|
51
42
|
mimeType: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as telemetry } from "../Telemetry-
|
|
2
|
-
import { n as getFileDataAfterUploadingToS3, t as downloadFileFromS3 } from "../fileUtils.node-
|
|
1
|
+
import { t as telemetry } from "../Telemetry-CF0rNHu2.mjs";
|
|
2
|
+
import { n as getFileDataAfterUploadingToS3, t as downloadFileFromS3 } from "../fileUtils.node-DOkW4PBg.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/models/Files.node.ts
|
|
5
5
|
var Files = class {
|
package/dist/platform/node.d.mts
CHANGED
package/dist/platform/node.mjs
CHANGED
|
@@ -1,4 +1,28 @@
|
|
|
1
1
|
//#region src/platform/workerd.ts
|
|
2
|
+
const SLASH_CHAR_CODE = 47;
|
|
3
|
+
/**
|
|
4
|
+
* Trailing-slash trim without a regex. The equivalent pattern backtracks
|
|
5
|
+
* quadratically on long runs of slashes (CodeQL js/polynomial-redos), so this
|
|
6
|
+
* walks the string from the end instead. Returns the input unchanged when
|
|
7
|
+
* there is nothing to trim, so the common case allocates nothing.
|
|
8
|
+
*/
|
|
9
|
+
const trimTrailingSlashes = (value) => {
|
|
10
|
+
let end = value.length;
|
|
11
|
+
while (end > 0 && value.charCodeAt(end - 1) === SLASH_CHAR_CODE) end--;
|
|
12
|
+
return end === value.length ? value : value.slice(0, end);
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Leading-and-trailing slash trim without a regex, matching the semantics of
|
|
16
|
+
* the previous leading/trailing slash-trim replace for every input, including
|
|
17
|
+
* a string that is entirely slashes.
|
|
18
|
+
*/
|
|
19
|
+
const trimSurroundingSlashes = (value) => {
|
|
20
|
+
let start = 0;
|
|
21
|
+
let end = value.length;
|
|
22
|
+
while (start < end && value.charCodeAt(start) === SLASH_CHAR_CODE) start++;
|
|
23
|
+
while (end > start && value.charCodeAt(end - 1) === SLASH_CHAR_CODE) end--;
|
|
24
|
+
return start === 0 && end === value.length ? value : value.slice(start, end);
|
|
25
|
+
};
|
|
2
26
|
/**
|
|
3
27
|
* Cloudflare Workers / Edge runtime platform implementation.
|
|
4
28
|
* Provides stub implementations for file system operations that are unavailable in edge runtimes.
|
|
@@ -11,8 +35,8 @@ const platform = {
|
|
|
11
35
|
},
|
|
12
36
|
joinPath(...paths) {
|
|
13
37
|
return paths.map((segment, index) => {
|
|
14
|
-
if (index === 0) return segment
|
|
15
|
-
return segment
|
|
38
|
+
if (index === 0) return trimTrailingSlashes(segment);
|
|
39
|
+
return trimSurroundingSlashes(segment);
|
|
16
40
|
}).filter(Boolean).join("/");
|
|
17
41
|
},
|
|
18
42
|
resolvePath(...paths) {
|
|
@@ -22,12 +46,15 @@ const platform = {
|
|
|
22
46
|
return filePath.startsWith("/");
|
|
23
47
|
},
|
|
24
48
|
basename(filePath) {
|
|
25
|
-
const segments = filePath
|
|
49
|
+
const segments = trimTrailingSlashes(filePath).split("/");
|
|
26
50
|
return segments[segments.length - 1] || "";
|
|
27
51
|
},
|
|
28
52
|
existsSync(_filePath) {
|
|
29
53
|
return false;
|
|
30
54
|
},
|
|
55
|
+
realpathSync(filePath) {
|
|
56
|
+
return filePath;
|
|
57
|
+
},
|
|
31
58
|
mkdirSync(_dirPath) {},
|
|
32
59
|
readFileSync(_filePath, _encoding) {
|
|
33
60
|
throw new Error("File system operations are not supported in this runtime environment (Cloudflare Workers/Edge). Use environment variables or external storage services instead.");
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { a as ComposioSensitiveFilePathBlockedError } from "./FileModifierErrors-B8V8_3VE.mjs";
|
|
2
|
+
import { platform } from "#platform";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/uuid.ts
|
|
5
|
+
function getRandomUUID() {
|
|
6
|
+
return globalThis.crypto.randomUUID();
|
|
7
|
+
}
|
|
8
|
+
function getRandomShortId() {
|
|
9
|
+
return getRandomUUID().slice(0, 8).replace(/-/g, "");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/utils/buffer.ts
|
|
14
|
+
/**
|
|
15
|
+
* Convert ArrayBuffer to base64.
|
|
16
|
+
*/
|
|
17
|
+
function arrayBufferToBase64(buffer) {
|
|
18
|
+
const bytes = new Uint8Array(buffer);
|
|
19
|
+
let binary = "";
|
|
20
|
+
for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
|
|
21
|
+
return btoa(binary);
|
|
22
|
+
}
|
|
23
|
+
const base64ToUint8Array = (base64) => {
|
|
24
|
+
const binary = atob(base64);
|
|
25
|
+
const bytes = new Uint8Array(binary.length);
|
|
26
|
+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
27
|
+
return bytes;
|
|
28
|
+
};
|
|
29
|
+
const uint8ArrayToBase64 = (bytes) => {
|
|
30
|
+
let binary = "";
|
|
31
|
+
for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
|
|
32
|
+
return btoa(binary);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/utils/readResponseBody.ts
|
|
37
|
+
/** Maximum size accepted for files fetched from user-supplied URLs (100 MiB). */
|
|
38
|
+
const MAX_URL_UPLOAD_SIZE_BYTES = 100 * 1024 * 1024;
|
|
39
|
+
const sizeLimitError = (actualSize, maxBytes) => /* @__PURE__ */ new Error(`File size (${actualSize} bytes) exceeds maximum allowed size (${maxBytes} bytes)`);
|
|
40
|
+
/**
|
|
41
|
+
* Read a fetch response without allowing an untrusted server to exhaust memory.
|
|
42
|
+
*
|
|
43
|
+
* `Content-Length` is checked as an early rejection, but the streamed byte
|
|
44
|
+
* count is authoritative because the header can be absent or dishonest.
|
|
45
|
+
*/
|
|
46
|
+
const readResponseBodyWithLimit = async (response, maxBytes = MAX_URL_UPLOAD_SIZE_BYTES) => {
|
|
47
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes < 0) throw new RangeError("maxBytes must be a non-negative safe integer");
|
|
48
|
+
const contentLength = response.headers.get("content-length")?.trim();
|
|
49
|
+
if (contentLength && /^\d+$/.test(contentLength)) {
|
|
50
|
+
const declaredSize = Number(contentLength);
|
|
51
|
+
if (!Number.isSafeInteger(declaredSize) || declaredSize > maxBytes) {
|
|
52
|
+
const error = sizeLimitError(declaredSize, maxBytes);
|
|
53
|
+
await response.body?.cancel(error).catch(() => void 0);
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (!response.body) return /* @__PURE__ */ new Uint8Array();
|
|
58
|
+
const reader = response.body.getReader();
|
|
59
|
+
const chunks = [];
|
|
60
|
+
let totalBytes = 0;
|
|
61
|
+
try {
|
|
62
|
+
while (true) {
|
|
63
|
+
const { done, value } = await reader.read();
|
|
64
|
+
if (done) break;
|
|
65
|
+
if (!value || value.byteLength === 0) continue;
|
|
66
|
+
totalBytes += value.byteLength;
|
|
67
|
+
if (totalBytes > maxBytes) {
|
|
68
|
+
await reader.cancel(sizeLimitError(totalBytes, maxBytes));
|
|
69
|
+
throw sizeLimitError(totalBytes, maxBytes);
|
|
70
|
+
}
|
|
71
|
+
chunks.push(value);
|
|
72
|
+
}
|
|
73
|
+
} finally {
|
|
74
|
+
reader.releaseLock();
|
|
75
|
+
}
|
|
76
|
+
const body = new Uint8Array(totalBytes);
|
|
77
|
+
let offset = 0;
|
|
78
|
+
for (const chunk of chunks) {
|
|
79
|
+
body.set(chunk, offset);
|
|
80
|
+
offset += chunk.byteLength;
|
|
81
|
+
}
|
|
82
|
+
return body;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region src/utils/sensitiveFileUploadPaths.ts
|
|
87
|
+
/**
|
|
88
|
+
* Blocks accidental upload of local files from well-known secret/credential locations
|
|
89
|
+
* during auto file upload (and {@link getFileDataAfterUploadingToS3}).
|
|
90
|
+
*
|
|
91
|
+
* This is the single canonical guard shared by the core SDK and downstream
|
|
92
|
+
* packages (e.g. `@composio/cli`). Filesystem access goes through the `#platform`
|
|
93
|
+
* abstraction so this module stays free of static `node:*` imports and is safe to
|
|
94
|
+
* re-export from the package root (edge/workerd builds included).
|
|
95
|
+
*/
|
|
96
|
+
/**
|
|
97
|
+
* Path segments (a single path component) that indicate a sensitive directory when
|
|
98
|
+
* they appear anywhere in a resolved local path. Compared case-insensitively on Windows.
|
|
99
|
+
*/
|
|
100
|
+
const BUILTIN_FILE_UPLOAD_PATH_DENY_SEGMENTS = [
|
|
101
|
+
".ssh",
|
|
102
|
+
".aws",
|
|
103
|
+
".azure",
|
|
104
|
+
".gnupg",
|
|
105
|
+
".kube",
|
|
106
|
+
".docker",
|
|
107
|
+
".claude",
|
|
108
|
+
".password-store",
|
|
109
|
+
"keychains"
|
|
110
|
+
];
|
|
111
|
+
const SECRET_LIKE_BASENAME = /^(\.env(\.|$)|\.netrc$|\.pgpass$)/i;
|
|
112
|
+
/** Default SSH private key basenames (public keys like id_rsa.pub are allowed). */
|
|
113
|
+
const DEFAULT_PRIVATE_KEY_BASENAME = /^id_(rsa|ed25519|ecdsa|dsa|ecdsa_sk)(\.old)?$/i;
|
|
114
|
+
const isWindows = typeof process !== "undefined" && process.platform === "win32";
|
|
115
|
+
/**
|
|
116
|
+
* Returns normalized path segments, resolving symlinks when the path exists.
|
|
117
|
+
*/
|
|
118
|
+
function normalizePathSegments(filePath) {
|
|
119
|
+
const absolute = platform.resolvePath(filePath);
|
|
120
|
+
let resolved = absolute;
|
|
121
|
+
try {
|
|
122
|
+
if (platform.existsSync(absolute)) resolved = platform.realpathSync(absolute);
|
|
123
|
+
} catch {}
|
|
124
|
+
return resolved.split(/[/\\]+/).filter(Boolean);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* True if the path is under a built-in or extra deny segment, or the basename
|
|
128
|
+
* looks like an env / netrc / default SSH private key name.
|
|
129
|
+
*/
|
|
130
|
+
function isBlockedSensitiveFileUploadPath(filePath, additionalDenySegments) {
|
|
131
|
+
return getSensitiveFileUploadPathBlockReason(filePath, additionalDenySegments) != null;
|
|
132
|
+
}
|
|
133
|
+
function getSensitiveFileUploadPathBlockReason(filePath, additionalDenySegments) {
|
|
134
|
+
const segments = normalizePathSegments(filePath);
|
|
135
|
+
const deny = new Set([...BUILTIN_FILE_UPLOAD_PATH_DENY_SEGMENTS, ...(additionalDenySegments ?? []).map((s) => s.trim()).filter(Boolean)].map((s) => isWindows ? s.toLowerCase() : s));
|
|
136
|
+
const segmentsForMatch = isWindows ? segments.map((s) => s.toLowerCase()) : segments;
|
|
137
|
+
for (let i = 0; i < segments.length; i++) if (deny.has(segmentsForMatch[i])) return `path segment "${segments[i]}" is in the sensitive file upload denylist`;
|
|
138
|
+
const basename = segments.length > 0 ? segments[segments.length - 1] : "";
|
|
139
|
+
if (basename) {
|
|
140
|
+
if (SECRET_LIKE_BASENAME.test(basename) || DEFAULT_PRIVATE_KEY_BASENAME.test(basename)) return `file name "${basename}" looks like a credential, env, or private key file`;
|
|
141
|
+
if (basename.toLowerCase() === "credentials") return "file name \"credentials\" is often used for cloud/API credential stores";
|
|
142
|
+
}
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Default remediation hint appended to the block message. Assumes an SDK caller
|
|
147
|
+
* that exposes `sensitiveFileUploadProtection`. Callers without such an opt-out
|
|
148
|
+
* (e.g. `@composio/cli`) should pass their own `remediation` so the message does
|
|
149
|
+
* not advertise an option the caller cannot honor.
|
|
150
|
+
*/
|
|
151
|
+
const DEFAULT_REMEDIATION = "To upload from this path anyway, set sensitiveFileUploadProtection: false on Composio (not recommended) or use a copy outside sensitive locations.";
|
|
152
|
+
/**
|
|
153
|
+
* @throws {ComposioSensitiveFilePathBlockedError} if the path is not allowed
|
|
154
|
+
*/
|
|
155
|
+
function assertSafeFileUploadPath(filePath, options) {
|
|
156
|
+
const reason = getSensitiveFileUploadPathBlockReason(filePath, options?.additionalDenySegments);
|
|
157
|
+
if (reason) throw new ComposioSensitiveFilePathBlockedError(`Refusing to upload: ${reason}. ${options?.remediation ?? DEFAULT_REMEDIATION}`, { meta: {
|
|
158
|
+
filePath,
|
|
159
|
+
reason
|
|
160
|
+
} });
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
//#endregion
|
|
164
|
+
export { arrayBufferToBase64 as a, getRandomShortId as c, readResponseBodyWithLimit as i, getRandomUUID as l, assertSafeFileUploadPath as n, base64ToUint8Array as o, isBlockedSensitiveFileUploadPath as r, uint8ArrayToBase64 as s, BUILTIN_FILE_UPLOAD_PATH_DENY_SEGMENTS as t };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { n as BaseComposioProvider } from "./BaseProvider-
|
|
2
|
-
import { n as ComposioConfig } from "./composio-
|
|
3
|
-
|
|
1
|
+
import { n as BaseComposioProvider } from "./BaseProvider-Dc5yKZhk.mjs";
|
|
2
|
+
import { n as ComposioConfig } from "./composio-ChU3eD9F.mjs";
|
|
4
3
|
//#region src/utils/config-defaults/types.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Configuration defaults for Composio.
|
|
@@ -37,6 +37,15 @@ interface Platform {
|
|
|
37
37
|
* @returns True if the path exists, false otherwise.
|
|
38
38
|
*/
|
|
39
39
|
existsSync(filePath: string): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Resolves symlinks in a path, returning the canonical absolute path. On Node
|
|
42
|
+
* this is `fs.realpathSync`; on edge runtimes without a filesystem it returns
|
|
43
|
+
* the input path unchanged (best-effort). Used to prevent a symlink from
|
|
44
|
+
* smuggling an upload past the sensitive-path denylist.
|
|
45
|
+
* @param filePath - The path to canonicalize.
|
|
46
|
+
* @returns The resolved path, or the input path if it cannot be resolved.
|
|
47
|
+
*/
|
|
48
|
+
realpathSync(filePath: string): string;
|
|
40
49
|
/**
|
|
41
50
|
* Creates a directory at the given path, including parent directories if needed.
|
|
42
51
|
* @param dirPath - The directory path to create.
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { gn as Tool, xn as ToolExecuteResponse, yn as ToolExecuteParams } from "../../BaseProvider-
|
|
1
|
+
import { gn as Tool, xn as ToolExecuteResponse, yn as ToolExecuteParams } from "../../BaseProvider-Dc5yKZhk.mjs";
|
|
2
2
|
import ComposioClient from "@composio/client";
|
|
3
|
-
|
|
4
3
|
//#region src/utils/modifiers/FileToolModifier.node.d.ts
|
|
5
4
|
declare class FileToolModifier {
|
|
6
5
|
private client;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { i as logger } from "../../SsrfErrors-DNJt57GL.mjs";
|
|
2
|
+
import { f as ComposioRequestCancelledError } from "../../errors-BcEUHZbq.mjs";
|
|
3
|
+
import { a as ComposioSensitiveFilePathBlockedError, i as ComposioFileUploadPathNotAllowedError, n as ComposioFileUploadAbortedError, r as ComposioFileUploadError, t as ComposioFileNotFoundError } from "../../FileModifierErrors-B8V8_3VE.mjs";
|
|
3
4
|
import { i as transformProperties, n as schemaHasFileProperty, t as isPlainObject } from "../../FileToolModifier.utils.neutral-B5rT711M.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import { n as getFileDataAfterUploadingToS3, t as downloadFileFromS3 } from "../../fileUtils.node-
|
|
5
|
+
import { r as dereferenceJsonSchema, t as withCancellation } from "../../cancellation-BbJ-UQ__.mjs";
|
|
6
|
+
import { n as getFileDataAfterUploadingToS3, r as isHttpUrl, t as downloadFileFromS3 } from "../../fileUtils.node-DOkW4PBg.mjs";
|
|
6
7
|
|
|
7
8
|
//#region src/utils/modifiers/FileToolModifier.node.ts
|
|
8
9
|
/**
|
|
@@ -68,7 +69,7 @@ const hydrateFiles = async (value, schema, ctx) => {
|
|
|
68
69
|
return out;
|
|
69
70
|
};
|
|
70
71
|
if (typeof value === "string") {
|
|
71
|
-
const pathOrUrl = await runBeforeFileUpload(value, value
|
|
72
|
+
const pathOrUrl = await runBeforeFileUpload(value, isHttpUrl(value) ? "url" : "path");
|
|
72
73
|
logger.debug(`Uploading file "${pathOrUrl}"`);
|
|
73
74
|
return getFileDataAfterUploadingToS3(pathOrUrl, {
|
|
74
75
|
toolSlug: ctx.toolSlug,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { gn as Tool, xn as ToolExecuteResponse, yn as ToolExecuteParams } from "../../BaseProvider-
|
|
1
|
+
import { gn as Tool, xn as ToolExecuteResponse, yn as ToolExecuteParams } from "../../BaseProvider-Dc5yKZhk.mjs";
|
|
2
2
|
import ComposioClient from "@composio/client";
|
|
3
|
-
|
|
4
3
|
//#region src/utils/modifiers/FileToolModifier.workerd.d.ts
|
|
5
4
|
declare class FileToolModifier {
|
|
6
5
|
constructor(_client: ComposioClient);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/utils/ssrfGuard.node.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* True when `ip` is a private, loopback, link-local, or otherwise
|
|
4
|
+
* non-publicly-routable address. Fails closed (returns `true`) for anything that
|
|
5
|
+
* is not a valid IPv4/IPv6 literal.
|
|
6
|
+
*/
|
|
7
|
+
declare const isBlockedIp: (ip: string) => boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Validate a single URL: it must be http(s), its host must resolve, and every
|
|
10
|
+
* resolved address must be publicly routable. Throws
|
|
11
|
+
* {@link ComposioBlockedInternalUrlError} otherwise.
|
|
12
|
+
*/
|
|
13
|
+
declare const assertSafeFetchTarget: (rawUrl: string) => Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Drop-in replacement for `fetch` that blocks SSRF. Validates the target before
|
|
16
|
+
* connecting and re-validates every redirect hop (redirects are followed
|
|
17
|
+
* manually up to {@link MAX_REDIRECTS}). Non-redirect responses are returned
|
|
18
|
+
* unchanged.
|
|
19
|
+
*/
|
|
20
|
+
declare const ssrfSafeFetch: (rawUrl: string, init?: RequestInit, maxRedirects?: number) => Promise<Response>;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { assertSafeFetchTarget, isBlockedIp, ssrfSafeFetch };
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { t as ComposioBlockedInternalUrlError } from "../SsrfErrors-DNJt57GL.mjs";
|
|
2
|
+
import { lookup } from "node:dns/promises";
|
|
3
|
+
import { isIP } from "node:net";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/ssrfGuard.node.ts
|
|
6
|
+
/**
|
|
7
|
+
* SSRF guard for user-supplied URL file inputs.
|
|
8
|
+
*
|
|
9
|
+
* `composio.files.upload(url)`, Tool Router session file uploads, and automatic
|
|
10
|
+
* file upload during tool execution fetch arbitrary user-provided URLs. Without
|
|
11
|
+
* a guard, a caller (or a tool argument produced by an LLM) can point the SDK at
|
|
12
|
+
* internal infrastructure — loopback, RFC1918 ranges, link-local cloud-metadata
|
|
13
|
+
* endpoints (`169.254.169.254`), or a public URL that 3xx-redirects into internal
|
|
14
|
+
* space — turning the SDK into a server-side request forgery probe.
|
|
15
|
+
*
|
|
16
|
+
* This module validates the *resolved* address (not just the hostname string,
|
|
17
|
+
* which defeats decimal/octal/hex IP obfuscation) before every fetch, and
|
|
18
|
+
* follows redirects manually so each hop is re-validated.
|
|
19
|
+
*
|
|
20
|
+
* Known residual: a DNS name could resolve to a public address here and rebind
|
|
21
|
+
* to an internal one before the underlying `fetch` connects (a TOCTOU / DNS
|
|
22
|
+
* rebinding window). Closing that fully requires pinning the validated IP at
|
|
23
|
+
* connect time (a custom dispatcher), which is out of scope for this guard.
|
|
24
|
+
*/
|
|
25
|
+
const MAX_REDIRECTS = 5;
|
|
26
|
+
const ipv4ToLong = (ip) => {
|
|
27
|
+
const [a, b, c, d] = ip.split(".").map(Number);
|
|
28
|
+
return (a << 24 >>> 0 | b << 16 | c << 8 | d) >>> 0;
|
|
29
|
+
};
|
|
30
|
+
const IPV4_BLOCKED_CIDRS = [
|
|
31
|
+
["0.0.0.0", 8],
|
|
32
|
+
["10.0.0.0", 8],
|
|
33
|
+
["100.64.0.0", 10],
|
|
34
|
+
["127.0.0.0", 8],
|
|
35
|
+
["169.254.0.0", 16],
|
|
36
|
+
["172.16.0.0", 12],
|
|
37
|
+
["192.0.0.0", 24],
|
|
38
|
+
["192.0.2.0", 24],
|
|
39
|
+
["192.168.0.0", 16],
|
|
40
|
+
["198.18.0.0", 15],
|
|
41
|
+
["198.51.100.0", 24],
|
|
42
|
+
["203.0.113.0", 24],
|
|
43
|
+
["224.0.0.0", 4],
|
|
44
|
+
["240.0.0.0", 4]
|
|
45
|
+
];
|
|
46
|
+
const isBlockedIpv4Long = (long) => IPV4_BLOCKED_CIDRS.some(([base, bits]) => {
|
|
47
|
+
const mask = bits === 0 ? 0 : 4294967295 << 32 - bits >>> 0;
|
|
48
|
+
return (long & mask) === (ipv4ToLong(base) & mask);
|
|
49
|
+
});
|
|
50
|
+
/**
|
|
51
|
+
* Expand an IPv6 string into its 8 16-bit groups, converting any trailing
|
|
52
|
+
* dotted-quad (e.g. `::ffff:1.2.3.4`) into hex groups first. Returns `null` when
|
|
53
|
+
* the input cannot be parsed.
|
|
54
|
+
*/
|
|
55
|
+
const expandIpv6 = (ip) => {
|
|
56
|
+
let addr = ip;
|
|
57
|
+
const v4Match = addr.match(/^(.*:)(\d+\.\d+\.\d+\.\d+)$/);
|
|
58
|
+
if (v4Match) {
|
|
59
|
+
const long = ipv4ToLong(v4Match[2]);
|
|
60
|
+
addr = `${v4Match[1]}${(long >>> 16 & 65535).toString(16)}:${(long & 65535).toString(16)}`;
|
|
61
|
+
}
|
|
62
|
+
const halves = addr.split("::");
|
|
63
|
+
if (halves.length > 2) return null;
|
|
64
|
+
const head = halves[0] ? halves[0].split(":") : [];
|
|
65
|
+
const tail = halves.length === 2 ? halves[1] ? halves[1].split(":") : [] : [];
|
|
66
|
+
let groups;
|
|
67
|
+
if (halves.length === 2) {
|
|
68
|
+
const missing = 8 - head.length - tail.length;
|
|
69
|
+
if (missing < 0) return null;
|
|
70
|
+
groups = [
|
|
71
|
+
...head,
|
|
72
|
+
...Array(missing).fill("0"),
|
|
73
|
+
...tail
|
|
74
|
+
];
|
|
75
|
+
} else groups = head;
|
|
76
|
+
if (groups.length !== 8) return null;
|
|
77
|
+
return groups.map((g) => parseInt(g || "0", 16));
|
|
78
|
+
};
|
|
79
|
+
const isBlockedIpv6 = (ip) => {
|
|
80
|
+
const h = expandIpv6(ip);
|
|
81
|
+
if (!h) return true;
|
|
82
|
+
if (h.every((x) => x === 0)) return true;
|
|
83
|
+
if (h.slice(0, 7).every((x) => x === 0) && h[7] === 1) return true;
|
|
84
|
+
const isMappedOrCompat = h[0] === 0 && h[1] === 0 && h[2] === 0 && h[3] === 0 && h[4] === 0 && (h[5] === 65535 || h[5] === 0);
|
|
85
|
+
const isNat64 = h[0] === 100 && h[1] === 65435 && h[2] === 0 && h[3] === 0 && h[4] === 0 && h[5] === 0;
|
|
86
|
+
if (isMappedOrCompat || isNat64) return isBlockedIpv4Long((h[6] << 16 >>> 0 | h[7]) >>> 0);
|
|
87
|
+
if ((h[0] & 65024) === 64512) return true;
|
|
88
|
+
if ((h[0] & 65472) === 65152) return true;
|
|
89
|
+
if ((h[0] & 65280) === 65280) return true;
|
|
90
|
+
return false;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* True when `ip` is a private, loopback, link-local, or otherwise
|
|
94
|
+
* non-publicly-routable address. Fails closed (returns `true`) for anything that
|
|
95
|
+
* is not a valid IPv4/IPv6 literal.
|
|
96
|
+
*/
|
|
97
|
+
const isBlockedIp = (ip) => {
|
|
98
|
+
const family = isIP(ip);
|
|
99
|
+
if (family === 4) return isBlockedIpv4Long(ipv4ToLong(ip));
|
|
100
|
+
if (family === 6) return isBlockedIpv6(ip);
|
|
101
|
+
return true;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Validate a single URL: it must be http(s), its host must resolve, and every
|
|
105
|
+
* resolved address must be publicly routable. Throws
|
|
106
|
+
* {@link ComposioBlockedInternalUrlError} otherwise.
|
|
107
|
+
*/
|
|
108
|
+
const assertSafeFetchTarget = async (rawUrl) => {
|
|
109
|
+
let url;
|
|
110
|
+
try {
|
|
111
|
+
url = new URL(rawUrl);
|
|
112
|
+
} catch {
|
|
113
|
+
throw new ComposioBlockedInternalUrlError("Refusing to fetch a malformed URL", { url: rawUrl });
|
|
114
|
+
}
|
|
115
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") throw new ComposioBlockedInternalUrlError(`Refusing to fetch a non-http(s) URL (scheme "${url.protocol}")`, { url: rawUrl });
|
|
116
|
+
const host = url.hostname.replace(/^\[|\]$/g, "");
|
|
117
|
+
let resolved;
|
|
118
|
+
try {
|
|
119
|
+
resolved = await lookup(host, {
|
|
120
|
+
all: true,
|
|
121
|
+
verbatim: true
|
|
122
|
+
});
|
|
123
|
+
} catch {
|
|
124
|
+
throw new ComposioBlockedInternalUrlError(`Could not resolve host "${host}"`, { url: rawUrl });
|
|
125
|
+
}
|
|
126
|
+
for (const { address } of resolved) if (isBlockedIp(address)) throw new ComposioBlockedInternalUrlError(`Refusing to fetch "${host}" — it resolves to a private, loopback, or link-local address`, {
|
|
127
|
+
url: rawUrl,
|
|
128
|
+
resolvedIp: address
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Drop-in replacement for `fetch` that blocks SSRF. Validates the target before
|
|
133
|
+
* connecting and re-validates every redirect hop (redirects are followed
|
|
134
|
+
* manually up to {@link MAX_REDIRECTS}). Non-redirect responses are returned
|
|
135
|
+
* unchanged.
|
|
136
|
+
*/
|
|
137
|
+
const ssrfSafeFetch = async (rawUrl, init = {}, maxRedirects = MAX_REDIRECTS) => {
|
|
138
|
+
let currentUrl = rawUrl;
|
|
139
|
+
for (let hop = 0; hop <= maxRedirects; hop++) {
|
|
140
|
+
await assertSafeFetchTarget(currentUrl);
|
|
141
|
+
const response = await fetch(currentUrl, {
|
|
142
|
+
...init,
|
|
143
|
+
redirect: "manual"
|
|
144
|
+
});
|
|
145
|
+
if (!(response.status >= 300 && response.status < 400 && response.headers.has("location"))) return response;
|
|
146
|
+
currentUrl = new URL(response.headers.get("location"), currentUrl).toString();
|
|
147
|
+
}
|
|
148
|
+
throw new ComposioBlockedInternalUrlError(`Refusing to fetch: too many redirects (max ${maxRedirects})`, { url: rawUrl });
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
//#endregion
|
|
152
|
+
export { assertSafeFetchTarget, isBlockedIp, ssrfSafeFetch };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/utils/ssrfGuard.workerd.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Edge runtimes do not expose the DNS resolution APIs needed to prove that a
|
|
4
|
+
* hostname is publicly routable before connecting. Fail closed instead of
|
|
5
|
+
* falling back to an unguarded fetch.
|
|
6
|
+
*/
|
|
7
|
+
declare const ssrfSafeFetch: (rawUrl: string) => Promise<Response>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { ssrfSafeFetch };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { t as ComposioBlockedInternalUrlError } from "../SsrfErrors-DNJt57GL.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/ssrfGuard.workerd.ts
|
|
4
|
+
/**
|
|
5
|
+
* Edge runtimes do not expose the DNS resolution APIs needed to prove that a
|
|
6
|
+
* hostname is publicly routable before connecting. Fail closed instead of
|
|
7
|
+
* falling back to an unguarded fetch.
|
|
8
|
+
*/
|
|
9
|
+
const ssrfSafeFetch = async (rawUrl) => {
|
|
10
|
+
throw new ComposioBlockedInternalUrlError("URL file uploads are not supported in edge runtimes because the destination cannot be safely validated", {
|
|
11
|
+
url: rawUrl,
|
|
12
|
+
possibleFixes: ["Fetch the public URL yourself and pass a File or ArrayBuffer instead", "Run the URL upload in a Node.js or Bun runtime"]
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { ssrfSafeFetch };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@composio/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.14.1",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
7
7
|
"publishConfig": {
|
|
@@ -31,6 +31,12 @@
|
|
|
31
31
|
"edge-light": "./dist/utils/config-defaults/ConfigDefaults.workerd.mjs",
|
|
32
32
|
"node": "./dist/utils/config-defaults/ConfigDefaults.node.mjs",
|
|
33
33
|
"default": "./dist/utils/config-defaults/ConfigDefaults.node.mjs"
|
|
34
|
+
},
|
|
35
|
+
"#ssrf_guard": {
|
|
36
|
+
"workerd": "./dist/utils/ssrfGuard.workerd.mjs",
|
|
37
|
+
"edge-light": "./dist/utils/ssrfGuard.workerd.mjs",
|
|
38
|
+
"node": "./dist/utils/ssrfGuard.node.mjs",
|
|
39
|
+
"default": "./dist/utils/ssrfGuard.node.mjs"
|
|
34
40
|
}
|
|
35
41
|
},
|
|
36
42
|
"exports": {
|
|
@@ -85,25 +91,25 @@
|
|
|
85
91
|
"devDependencies": {
|
|
86
92
|
"@type-challenges/utils": "^0.1.1",
|
|
87
93
|
"@types/semver": "^7.7.1",
|
|
88
|
-
"tsdown": "^0.22.
|
|
89
|
-
"tsx": "^4.
|
|
90
|
-
"typedoc": "^0.28.
|
|
91
|
-
"typescript": "
|
|
92
|
-
"vitest": "^4.1.
|
|
94
|
+
"tsdown": "^0.22.14",
|
|
95
|
+
"tsx": "^4.23.1",
|
|
96
|
+
"typedoc": "^0.28.20",
|
|
97
|
+
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
98
|
+
"vitest": "^4.1.10",
|
|
93
99
|
"zod": "^4.4.3"
|
|
94
100
|
},
|
|
95
101
|
"peerDependencies": {
|
|
96
|
-
"zod": "
|
|
102
|
+
"zod": ">=3.25.76 <5"
|
|
97
103
|
},
|
|
98
104
|
"dependencies": {
|
|
99
|
-
"@composio/client": "0.1.0-alpha.
|
|
105
|
+
"@composio/client": "0.1.0-alpha.76",
|
|
100
106
|
"@types/json-schema": "^7.0.15",
|
|
101
|
-
"openai": "^6.
|
|
107
|
+
"openai": "^6.49.0",
|
|
102
108
|
"picocolors": "^1.1.1",
|
|
103
|
-
"pusher-js": "^8.
|
|
104
|
-
"semver": "^7.8.
|
|
109
|
+
"pusher-js": "^8.6.0",
|
|
110
|
+
"semver": "^7.8.5",
|
|
105
111
|
"zod-to-json-schema": "^3.25.2",
|
|
106
|
-
"@composio/json-schema-to-zod": "0.2.
|
|
112
|
+
"@composio/json-schema-to-zod": "0.2.1"
|
|
107
113
|
},
|
|
108
114
|
"gitHead": "4fae6e54d5c150fba955cc5fa314281da5a1e064",
|
|
109
115
|
"repository": {
|
|
@@ -114,13 +120,12 @@
|
|
|
114
120
|
"bugs": {
|
|
115
121
|
"url": "https://github.com/ComposioHQ/composio/issues"
|
|
116
122
|
},
|
|
117
|
-
"homepage": "https://github.com/ComposioHQ/composio/tree/
|
|
123
|
+
"homepage": "https://github.com/ComposioHQ/composio/tree/next/ts/packages/core#readme",
|
|
118
124
|
"scripts": {
|
|
119
125
|
"clean": "git clean -xdf node_modules",
|
|
120
126
|
"build": "pnpm exec tsdown",
|
|
121
127
|
"test": "vitest run",
|
|
122
|
-
"typecheck": "
|
|
123
|
-
"typecheck:tsc": "tsc --noEmit --skipLibCheck && tsc --noEmit --skipLibCheck -p tsconfig.type-tests.json",
|
|
128
|
+
"typecheck": "tsc --noEmit --skipLibCheck && tsc --noEmit --skipLibCheck -p tsconfig.type-tests.json",
|
|
124
129
|
"generate:docs": "tsx scripts/generate-docs.ts"
|
|
125
130
|
},
|
|
126
131
|
"types": "dist/index.d.mts"
|