@composio/core 0.14.0 → 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.
Files changed (41) hide show
  1. package/dist/{BaseProvider-lCxnjFKQ.d.mts → BaseProvider-Dc5yKZhk.d.mts} +81 -82
  2. package/dist/{CustomTool-CmokRT9q.d.mts → CustomTool-4nVuwLzO.d.mts} +1 -2
  3. package/dist/{CustomTool-C_5NvBsX.mjs → CustomTool-l-j5HtEf.mjs} +1 -1
  4. package/dist/FileModifierErrors-B8V8_3VE.mjs +97 -0
  5. package/dist/{SsrfErrors-BQRozkeU.mjs → SsrfErrors-DNJt57GL.mjs} +5 -98
  6. package/dist/{Telemetry-llfvticE.mjs → Telemetry-CF0rNHu2.mjs} +2 -2
  7. package/dist/{cancellation-W65QRyj2.mjs → cancellation-BbJ-UQ__.mjs} +2 -2
  8. package/dist/{composio-6C8kHtqc.d.mts → composio-ChU3eD9F.d.mts} +260 -257
  9. package/dist/{customTool.types-kFhNYuzh.d.mts → customTool.types-CX2-LbfI.d.mts} +142 -109
  10. package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +2 -0
  11. package/dist/{errors-B165yJUQ.mjs → errors-BcEUHZbq.mjs} +2 -1
  12. package/dist/experimental/index.d.mts +2 -2
  13. package/dist/experimental/index.mjs +1 -1
  14. package/dist/{fileUtils.node-iPFi2o4i.mjs → fileUtils.node-DOkW4PBg.mjs} +5 -153
  15. package/dist/index.d.mts +1585 -753
  16. package/dist/index.mjs +14 -10
  17. package/dist/models/Files.node.d.mts +2 -11
  18. package/dist/models/Files.node.mjs +2 -2
  19. package/dist/models/Files.workerd.d.mts +0 -1
  20. package/dist/platform/node.d.mts +0 -1
  21. package/dist/platform/workerd.d.mts +0 -1
  22. package/dist/platform/workerd.mjs +27 -3
  23. package/dist/{sensitiveFileUploadPaths-B1OLsd8F.mjs → sensitiveFileUploadPaths-C43dHP7S.mjs} +52 -2
  24. package/dist/{types-yCrveqAj.d.mts → types-D5N60gUD.d.mts} +2 -3
  25. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -2
  26. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -2
  27. package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -2
  28. package/dist/utils/modifiers/FileToolModifier.node.mjs +5 -4
  29. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -2
  30. package/dist/utils/ssrfGuard.node.d.mts +22 -0
  31. package/dist/utils/ssrfGuard.node.mjs +152 -0
  32. package/dist/utils/ssrfGuard.workerd.d.mts +9 -0
  33. package/dist/utils/ssrfGuard.workerd.mjs +17 -0
  34. package/package.json +14 -9
  35. package/src/errors/SsrfErrors.ts +4 -3
  36. package/src/models/ToolRouterSessionFileMount.ts +7 -3
  37. package/src/platform/workerd.ts +30 -3
  38. package/src/utils/fileUtils.node.ts +2 -2
  39. package/src/utils/readResponseBody.ts +63 -0
  40. package/src/utils/ssrfGuard.node.ts +6 -6
  41. package/src/utils/ssrfGuard.workerd.ts +19 -0
@@ -126,6 +126,8 @@ Uploads a file to the session's file mount.
126
126
 
127
127
  Accepts a file path (local or URL), a native File object, or a raw buffer.
128
128
  The file is stored in the virtual filesystem associated with the tool router session.
129
+ URL inputs require a Node.js or Bun runtime so the destination can be DNS-validated;
130
+ edge runtimes must fetch the file themselves and pass a File or ArrayBuffer.
129
131
 
130
132
  ```typescript
131
133
  async upload(input: string | File | ArrayBuffer | Uint8Array, options?: ToolRouterSessionFilesMountUploadOptions): Promise<RemoteFile>
@@ -1,4 +1,5 @@
1
- import { l as ComposioError$1 } from "./SsrfErrors-BQRozkeU.mjs";
1
+ import { r as ComposioError$1 } from "./SsrfErrors-DNJt57GL.mjs";
2
+ import "./FileModifierErrors-B8V8_3VE.mjs";
2
3
  import { APIError, APIUserAbortError } from "@composio/client";
3
4
  import { ZodError } from "zod/v3";
4
5
 
@@ -1,3 +1,3 @@
1
- import { S as SessionContext, a as CreateCustomToolkitParams, c as CustomToolExecuteFn, f as CustomToolkit, o as CustomTool, r as CreateCustomToolParams } from "../customTool.types-kFhNYuzh.mjs";
2
- import { n as createCustomToolkit, t as createCustomTool } from "../CustomTool-CmokRT9q.mjs";
1
+ import { S as SessionContext, a as CreateCustomToolkitParams, c as CustomToolExecuteFn, f as CustomToolkit, o as CustomTool, r as CreateCustomToolParams } from "../customTool.types-CX2-LbfI.mjs";
2
+ import { n as createCustomToolkit, t as createCustomTool } from "../CustomTool-4nVuwLzO.mjs";
3
3
  export { type CreateCustomToolParams, type CreateCustomToolkitParams, type CustomTool, type CustomToolExecuteFn, type CustomToolkit, type SessionContext, createCustomTool as experimental_createTool, createCustomToolkit as experimental_createToolkit };
@@ -1,3 +1,3 @@
1
- import { a as createCustomToolkit, i as createCustomTool } from "../CustomTool-C_5NvBsX.mjs";
1
+ import { a as createCustomToolkit, i as createCustomTool } from "../CustomTool-l-j5HtEf.mjs";
2
2
 
3
3
  export { createCustomTool as experimental_createTool, createCustomToolkit as experimental_createToolkit };
@@ -1,11 +1,11 @@
1
- import { d as COMPOSIO_DIR, g as TEMP_FILES_DIRECTORY_NAME, o as ComposioFileUploadPathNotAllowedError, r as ComposioFileNotFoundError, t as ComposioBlockedInternalUrlError, u as logger } from "./SsrfErrors-BQRozkeU.mjs";
2
- import { a as base64ToUint8Array, n as assertSafeFileUploadPath, o as uint8ArrayToBase64, s as getRandomShortId } from "./sensitiveFileUploadPaths-B1OLsd8F.mjs";
1
+ import { a as COMPOSIO_DIR, i as logger, u as TEMP_FILES_DIRECTORY_NAME } from "./SsrfErrors-DNJt57GL.mjs";
2
+ import { i as ComposioFileUploadPathNotAllowedError, t as ComposioFileNotFoundError } from "./FileModifierErrors-B8V8_3VE.mjs";
3
+ import { c as getRandomShortId, i as readResponseBodyWithLimit, n as assertSafeFileUploadPath, o as base64ToUint8Array, s as uint8ArrayToBase64 } from "./sensitiveFileUploadPaths-C43dHP7S.mjs";
4
+ import { ssrfSafeFetch } from "./utils/ssrfGuard.node.mjs";
3
5
  import { platform } from "#platform";
4
6
  import fs from "node:fs";
5
7
  import * as path from "node:path";
6
8
  import crypto from "node:crypto";
7
- import { lookup } from "node:dns/promises";
8
- import { isIP } from "node:net";
9
9
 
10
10
  //#region src/utils/uploadDirAllowlist.node.ts
11
11
  /**
@@ -151,153 +151,6 @@ function assertPathInsideUploadDirs(filePath, allowlist) {
151
151
  } });
152
152
  }
153
153
 
154
- //#endregion
155
- //#region src/utils/ssrfGuard.node.ts
156
- /**
157
- * SSRF guard for user-supplied URL file inputs.
158
- *
159
- * `composio.files.upload(url)` and automatic file upload during tool execution
160
- * fetch arbitrary user-provided URLs. Without a guard, a caller (or a tool
161
- * argument produced by an LLM) can point the SDK at internal infrastructure —
162
- * loopback, RFC1918 ranges, link-local cloud-metadata endpoints
163
- * (`169.254.169.254`), or a public URL that 3xx-redirects into internal space —
164
- * turning the SDK into a server-side request forgery probe.
165
- *
166
- * This module validates the *resolved* address (not just the hostname string,
167
- * which defeats decimal/octal/hex IP obfuscation) before every fetch, and
168
- * follows redirects manually so each hop is re-validated.
169
- *
170
- * Known residual: a DNS name could resolve to a public address here and rebind
171
- * to an internal one before the underlying `fetch` connects (a TOCTOU / DNS
172
- * rebinding window). Closing that fully requires pinning the validated IP at
173
- * connect time (a custom dispatcher), which is out of scope for this guard.
174
- */
175
- const MAX_REDIRECTS = 5;
176
- const ipv4ToLong = (ip) => {
177
- const [a, b, c, d] = ip.split(".").map(Number);
178
- return (a << 24 >>> 0 | b << 16 | c << 8 | d) >>> 0;
179
- };
180
- const IPV4_BLOCKED_CIDRS = [
181
- ["0.0.0.0", 8],
182
- ["10.0.0.0", 8],
183
- ["100.64.0.0", 10],
184
- ["127.0.0.0", 8],
185
- ["169.254.0.0", 16],
186
- ["172.16.0.0", 12],
187
- ["192.0.0.0", 24],
188
- ["192.0.2.0", 24],
189
- ["192.168.0.0", 16],
190
- ["198.18.0.0", 15],
191
- ["198.51.100.0", 24],
192
- ["203.0.113.0", 24],
193
- ["224.0.0.0", 4],
194
- ["240.0.0.0", 4]
195
- ];
196
- const isBlockedIpv4Long = (long) => IPV4_BLOCKED_CIDRS.some(([base, bits]) => {
197
- const mask = bits === 0 ? 0 : 4294967295 << 32 - bits >>> 0;
198
- return (long & mask) === (ipv4ToLong(base) & mask);
199
- });
200
- /**
201
- * Expand an IPv6 string into its 8 16-bit groups, converting any trailing
202
- * dotted-quad (e.g. `::ffff:1.2.3.4`) into hex groups first. Returns `null` when
203
- * the input cannot be parsed.
204
- */
205
- const expandIpv6 = (ip) => {
206
- let addr = ip;
207
- const v4Match = addr.match(/^(.*:)(\d+\.\d+\.\d+\.\d+)$/);
208
- if (v4Match) {
209
- const long = ipv4ToLong(v4Match[2]);
210
- addr = `${v4Match[1]}${(long >>> 16 & 65535).toString(16)}:${(long & 65535).toString(16)}`;
211
- }
212
- const halves = addr.split("::");
213
- if (halves.length > 2) return null;
214
- const head = halves[0] ? halves[0].split(":") : [];
215
- const tail = halves.length === 2 ? halves[1] ? halves[1].split(":") : [] : [];
216
- let groups;
217
- if (halves.length === 2) {
218
- const missing = 8 - head.length - tail.length;
219
- if (missing < 0) return null;
220
- groups = [
221
- ...head,
222
- ...Array(missing).fill("0"),
223
- ...tail
224
- ];
225
- } else groups = head;
226
- if (groups.length !== 8) return null;
227
- return groups.map((g) => parseInt(g || "0", 16));
228
- };
229
- const isBlockedIpv6 = (ip) => {
230
- const h = expandIpv6(ip);
231
- if (!h) return true;
232
- if (h.every((x) => x === 0)) return true;
233
- if (h.slice(0, 7).every((x) => x === 0) && h[7] === 1) return true;
234
- const isMappedOrCompat = h[0] === 0 && h[1] === 0 && h[2] === 0 && h[3] === 0 && h[4] === 0 && (h[5] === 65535 || h[5] === 0);
235
- const isNat64 = h[0] === 100 && h[1] === 65435 && h[2] === 0 && h[3] === 0 && h[4] === 0 && h[5] === 0;
236
- if (isMappedOrCompat || isNat64) return isBlockedIpv4Long((h[6] << 16 >>> 0 | h[7]) >>> 0);
237
- if ((h[0] & 65024) === 64512) return true;
238
- if ((h[0] & 65472) === 65152) return true;
239
- if ((h[0] & 65280) === 65280) return true;
240
- return false;
241
- };
242
- /**
243
- * True when `ip` is a private, loopback, link-local, or otherwise
244
- * non-publicly-routable address. Fails closed (returns `true`) for anything that
245
- * is not a valid IPv4/IPv6 literal.
246
- */
247
- const isBlockedIp = (ip) => {
248
- const family = isIP(ip);
249
- if (family === 4) return isBlockedIpv4Long(ipv4ToLong(ip));
250
- if (family === 6) return isBlockedIpv6(ip);
251
- return true;
252
- };
253
- /**
254
- * Validate a single URL: it must be http(s), its host must resolve, and every
255
- * resolved address must be publicly routable. Throws
256
- * {@link ComposioBlockedInternalUrlError} otherwise.
257
- */
258
- const assertSafeFetchTarget = async (rawUrl) => {
259
- let url;
260
- try {
261
- url = new URL(rawUrl);
262
- } catch {
263
- throw new ComposioBlockedInternalUrlError("Refusing to fetch a malformed URL", { url: rawUrl });
264
- }
265
- if (url.protocol !== "http:" && url.protocol !== "https:") throw new ComposioBlockedInternalUrlError(`Refusing to fetch a non-http(s) URL (scheme "${url.protocol}")`, { url: rawUrl });
266
- const host = url.hostname.replace(/^\[|\]$/g, "");
267
- let resolved;
268
- try {
269
- resolved = await lookup(host, {
270
- all: true,
271
- verbatim: true
272
- });
273
- } catch {
274
- throw new ComposioBlockedInternalUrlError(`Could not resolve host "${host}"`, { url: rawUrl });
275
- }
276
- 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`, {
277
- url: rawUrl,
278
- resolvedIp: address
279
- });
280
- };
281
- /**
282
- * Drop-in replacement for `fetch` that blocks SSRF. Validates the target before
283
- * connecting and re-validates every redirect hop (redirects are followed
284
- * manually up to {@link MAX_REDIRECTS}). Non-redirect responses are returned
285
- * unchanged.
286
- */
287
- const ssrfSafeFetch = async (rawUrl, init = {}, maxRedirects = MAX_REDIRECTS) => {
288
- let currentUrl = rawUrl;
289
- for (let hop = 0; hop <= maxRedirects; hop++) {
290
- await assertSafeFetchTarget(currentUrl);
291
- const response = await fetch(currentUrl, {
292
- ...init,
293
- redirect: "manual"
294
- });
295
- if (!(response.status >= 300 && response.status < 400 && response.headers.has("location"))) return response;
296
- currentUrl = new URL(response.headers.get("location"), currentUrl).toString();
297
- }
298
- throw new ComposioBlockedInternalUrlError(`Refusing to fetch: too many redirects (max ${maxRedirects})`, { url: rawUrl });
299
- };
300
-
301
154
  //#endregion
302
155
  //#region src/utils/fileUtils.node.ts
303
156
  /**
@@ -400,8 +253,7 @@ const readFileContent = async (filePath) => {
400
253
  const readFileContentFromURL = async (path, signal) => {
401
254
  const response = await ssrfSafeFetch(path, { signal });
402
255
  if (!response.ok) throw new Error(`Failed to fetch file: ${response.statusText}`);
403
- const arrayBuffer = await response.arrayBuffer();
404
- const content = new Uint8Array(arrayBuffer);
256
+ const content = await readResponseBodyWithLimit(response);
405
257
  const mimeType = response.headers.get("content-type") || "application/octet-stream";
406
258
  const pathname = new URL(path).pathname;
407
259
  let fileName = platform.basename(pathname);