@composio/core 0.13.0 → 0.14.0
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-lCxnjFKQ.d.mts +29395 -0
- package/dist/{CustomTool-D9qwyMrv.mjs → CustomTool-C_5NvBsX.mjs} +17 -15
- package/dist/{CustomTool-DrJpOhY2.d.mts → CustomTool-CmokRT9q.d.mts} +1 -1
- package/dist/{FileModifierErrors-3fSwIWoa.mjs → SsrfErrors-BQRozkeU.mjs} +33 -1
- package/dist/{Telemetry-DhGI_J4G.mjs → Telemetry-llfvticE.mjs} +40 -8
- package/dist/{jsonSchema-CFKdONpP.mjs → cancellation-W65QRyj2.mjs} +64 -19
- package/dist/{composio-DHIKRdeG.d.mts → composio-6C8kHtqc.d.mts} +1079 -1092
- package/dist/{customTool.types-CKH2R2ia.d.mts → customTool.types-kFhNYuzh.d.mts} +602 -549
- package/dist/docs/reference/sdk-reference/typescript/index.mdx +1 -22
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +23 -0
- package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +24 -0
- package/dist/{errors-DSIlYfl5.mjs → errors-B165yJUQ.mjs} +74 -74
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/{fileUtils.node-BiO1JQsJ.mjs → fileUtils.node-iPFi2o4i.mjs} +182 -68
- package/dist/index.d.mts +1459 -1401
- package/dist/index.mjs +1437 -1375
- package/dist/models/Files.node.mjs +2 -2
- package/dist/platform/node.d.mts +1 -1
- package/dist/platform/node.mjs +3 -0
- package/dist/platform/workerd.d.mts +1 -1
- package/dist/platform/workerd.mjs +3 -0
- package/dist/sensitiveFileUploadPaths-B1OLsd8F.mjs +114 -0
- package/dist/{types-DdoCRzLj.d.mts → types-DY1r-kN9.d.mts} +9 -0
- package/dist/{types-D4Id3wXA.d.mts → types-yCrveqAj.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 +5 -5
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
- package/package.json +10 -10
- package/src/errors/SsrfErrors.ts +47 -0
- package/src/errors/index.ts +3 -0
- package/src/index.ts +10 -0
- package/src/lib/toolRouterSessionDelete.ts +30 -0
- package/src/models/CustomTool.ts +1 -3
- package/src/models/ToolRouter.ts +15 -0
- package/src/models/ToolRouterSession.ts +50 -16
- 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 +6 -0
- 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/types/toolRouter.types.ts +13 -0
- package/src/utils/fileUtils.node.ts +27 -4
- package/src/utils/jsonSchema.ts +58 -0
- package/src/utils/modifiers/FileToolModifier.node.ts +2 -1
- 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/toolkitVersion.ts +21 -2
- package/dist/BaseProvider-BBnsv9kS.d.mts +0 -29425
- package/dist/BaseProvider-Brb3o86-.d.mts +0 -29425
- package/dist/CustomTool-Dmi6ti3I.d.mts +0 -74
- package/dist/buffer-PcbMMsgm.mjs +0 -33
- package/dist/composio-vMwhASRc.d.mts +0 -5698
- package/dist/customTool.types-DXin7Cfc.d.mts +0 -2773
- package/dist/types-qTbYYBJw.d.mts +0 -12
|
@@ -5,28 +5,7 @@ description: "Complete API reference for the Composio TypeScript SDK (@composio/
|
|
|
5
5
|
|
|
6
6
|
## Installation
|
|
7
7
|
|
|
8
|
-
<
|
|
9
|
-
<Tab value="npm">
|
|
10
|
-
```bash
|
|
11
|
-
npm install @composio/core
|
|
12
|
-
```
|
|
13
|
-
</Tab>
|
|
14
|
-
<Tab value="pnpm">
|
|
15
|
-
```bash
|
|
16
|
-
pnpm add @composio/core
|
|
17
|
-
```
|
|
18
|
-
</Tab>
|
|
19
|
-
<Tab value="yarn">
|
|
20
|
-
```bash
|
|
21
|
-
yarn add @composio/core
|
|
22
|
-
```
|
|
23
|
-
</Tab>
|
|
24
|
-
<Tab value="bun">
|
|
25
|
-
```bash
|
|
26
|
-
bun add @composio/core
|
|
27
|
-
```
|
|
28
|
-
</Tab>
|
|
29
|
-
</Tabs>
|
|
8
|
+
<PackageInstall packages="@composio/core" />
|
|
30
9
|
|
|
31
10
|
## Classes
|
|
32
11
|
|
|
@@ -87,6 +87,29 @@ customTools(options?: { toolkit?: string }): RegisteredCustomTool[]
|
|
|
87
87
|
|
|
88
88
|
---
|
|
89
89
|
|
|
90
|
+
### delete()
|
|
91
|
+
|
|
92
|
+
Delete this session.
|
|
93
|
+
|
|
94
|
+
Deleted sessions immediately stop being retrievable or executable. Deleting
|
|
95
|
+
an already-deleted session surfaces the backend 404.
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
async delete(requestOptions?: ComposioRequestOptions): Promise<ToolRouterSessionDeleteResponse>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Parameters**
|
|
102
|
+
|
|
103
|
+
| Name | Type |
|
|
104
|
+
|------|------|
|
|
105
|
+
| `requestOptions?` | `ComposioRequestOptions` |
|
|
106
|
+
|
|
107
|
+
**Returns**
|
|
108
|
+
|
|
109
|
+
`Promise<ToolRouterSessionDeleteResponse>`
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
90
113
|
### execute()
|
|
91
114
|
|
|
92
115
|
Execute a tool within the session.
|
|
@@ -75,6 +75,30 @@ const session = await composio.sessions.create('user_123', {
|
|
|
75
75
|
|
|
76
76
|
---
|
|
77
77
|
|
|
78
|
+
### delete()
|
|
79
|
+
|
|
80
|
+
Delete a tool router session by ID.
|
|
81
|
+
|
|
82
|
+
Deleted sessions immediately stop being retrievable or executable. Deleting
|
|
83
|
+
a missing or already-deleted session surfaces the backend 404.
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
async delete(id: string, requestOptions?: ComposioRequestOptions): Promise<ToolRouterSessionDeleteResponse>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Parameters**
|
|
90
|
+
|
|
91
|
+
| Name | Type |
|
|
92
|
+
|------|------|
|
|
93
|
+
| `id` | `string` |
|
|
94
|
+
| `requestOptions?` | `ComposioRequestOptions` |
|
|
95
|
+
|
|
96
|
+
**Returns**
|
|
97
|
+
|
|
98
|
+
`Promise<ToolRouterSessionDeleteResponse>`
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
78
102
|
### use()
|
|
79
103
|
|
|
80
104
|
Use an existing session
|
|
@@ -1,7 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { l as ComposioError$1 } from "./SsrfErrors-BQRozkeU.mjs";
|
|
2
2
|
import { APIError, APIUserAbortError } from "@composio/client";
|
|
3
3
|
import { ZodError } from "zod/v3";
|
|
4
4
|
|
|
5
|
+
//#region src/errors/AuthConfigErrors.ts
|
|
6
|
+
const AuthConfigErrorCodes = { AUTH_CONFIG_NOT_FOUND: "AUTH_CONFIG_NOT_FOUND" };
|
|
7
|
+
var ComposioAuthConfigNotFoundError = class extends ComposioError$1 {
|
|
8
|
+
constructor(message = "Auth config not found", options = {}) {
|
|
9
|
+
super(message, {
|
|
10
|
+
...options,
|
|
11
|
+
code: AuthConfigErrorCodes.AUTH_CONFIG_NOT_FOUND,
|
|
12
|
+
possibleFixes: options.possibleFixes || [
|
|
13
|
+
"Check if the auth config exists",
|
|
14
|
+
"Check if the auth config id is correct",
|
|
15
|
+
"Check if the auth config is enabled"
|
|
16
|
+
]
|
|
17
|
+
});
|
|
18
|
+
this.name = "ComposioAuthConfigNotFoundError";
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
5
23
|
//#region src/errors/ConnectedAccountsErrors.ts
|
|
6
24
|
const ConnectedAccountErrorCodes = {
|
|
7
25
|
CONNECTED_ACCOUNT_NOT_FOUND: "CONNECTED_ACCOUNT_NOT_FOUND",
|
|
@@ -119,6 +137,31 @@ var ComposioLegacyConnectedAccountsEndpointRetiredError = class extends Composio
|
|
|
119
137
|
}
|
|
120
138
|
};
|
|
121
139
|
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/errors/ConnectionRequestErrors.ts
|
|
142
|
+
const ConnectionRequestErrorCodes = {
|
|
143
|
+
CONNECTION_REQUEST_TIMEOUT: "CONNECTION_REQUEST_TIMEOUT",
|
|
144
|
+
CONNECTION_REQUEST_FAILED: "CONNECTION_REQUEST_FAILED"
|
|
145
|
+
};
|
|
146
|
+
var ConnectionRequestTimeoutError = class extends ComposioError$1 {
|
|
147
|
+
constructor(message = "Connection request timed out", options = {}) {
|
|
148
|
+
super(message, {
|
|
149
|
+
...options,
|
|
150
|
+
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_TIMEOUT
|
|
151
|
+
});
|
|
152
|
+
this.name = "ConnectionRequestTimeoutError";
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
var ConnectionRequestFailedError = class extends ComposioError$1 {
|
|
156
|
+
constructor(message = "Connection request failed", options = {}) {
|
|
157
|
+
super(message, {
|
|
158
|
+
...options,
|
|
159
|
+
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_FAILED
|
|
160
|
+
});
|
|
161
|
+
this.name = "ConnectionRequestFailedError";
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
122
165
|
//#endregion
|
|
123
166
|
//#region src/errors/ToolErrors.ts
|
|
124
167
|
const ToolErrorCodes = {
|
|
@@ -279,7 +322,7 @@ var ComposioToolVersionRequiredError = class extends ComposioError$1 {
|
|
|
279
322
|
});
|
|
280
323
|
}
|
|
281
324
|
};
|
|
282
|
-
const ERROR_CODE_HANDLERS = new Map([[1803, (msg) => new ComposioConnectedAccountNotFoundError(msg)]]);
|
|
325
|
+
const ERROR_CODE_HANDLERS = /* @__PURE__ */ new Map([[1803, (msg) => new ComposioConnectedAccountNotFoundError(msg)]]);
|
|
283
326
|
const handleToolExecutionError = (tool, actualError) => {
|
|
284
327
|
if (actualError instanceof APIError && actualError.error) {
|
|
285
328
|
const errorBody = actualError.error;
|
|
@@ -293,6 +336,34 @@ const handleToolExecutionError = (tool, actualError) => {
|
|
|
293
336
|
});
|
|
294
337
|
};
|
|
295
338
|
|
|
339
|
+
//#endregion
|
|
340
|
+
//#region src/errors/ToolkitErrors.ts
|
|
341
|
+
const ToolkitErrorCodes = { TOOLKIT_NOT_FOUND: "TOOLKIT_NOT_FOUND" };
|
|
342
|
+
var ComposioToolkitNotFoundError = class extends ComposioError$1 {
|
|
343
|
+
constructor(message = "Toolkit not found", options = {}) {
|
|
344
|
+
super(message, {
|
|
345
|
+
...options,
|
|
346
|
+
code: "TOOLKIT_NOT_FOUND",
|
|
347
|
+
possibleFixes: options.possibleFixes || ["Ensure the toolkit is correctly configured and the slug is valid"]
|
|
348
|
+
});
|
|
349
|
+
this.name = "ComposioToolkitNotFoundError";
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
var ComposioToolkitFetchError = class extends ComposioError$1 {
|
|
353
|
+
constructor(message = "Failed to fetch toolkit", options = {}) {
|
|
354
|
+
super(message, {
|
|
355
|
+
...options,
|
|
356
|
+
code: "TOOLKIT_FETCH_ERROR",
|
|
357
|
+
possibleFixes: options.possibleFixes || [
|
|
358
|
+
"Ensure the toolkit slug is valid",
|
|
359
|
+
"Ensure you are using the correct API key",
|
|
360
|
+
"Ensure you are using the correct API endpoint / Base URL and it is working"
|
|
361
|
+
]
|
|
362
|
+
});
|
|
363
|
+
this.name = "ComposioToolkitFetchError";
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
|
|
296
367
|
//#endregion
|
|
297
368
|
//#region src/errors/ValidationErrors.ts
|
|
298
369
|
/**
|
|
@@ -420,77 +491,6 @@ function _isRequestAbortErrorAt(error, depth) {
|
|
|
420
491
|
return false;
|
|
421
492
|
}
|
|
422
493
|
|
|
423
|
-
//#endregion
|
|
424
|
-
//#region src/errors/AuthConfigErrors.ts
|
|
425
|
-
const AuthConfigErrorCodes = { AUTH_CONFIG_NOT_FOUND: "AUTH_CONFIG_NOT_FOUND" };
|
|
426
|
-
var ComposioAuthConfigNotFoundError = class extends ComposioError$1 {
|
|
427
|
-
constructor(message = "Auth config not found", options = {}) {
|
|
428
|
-
super(message, {
|
|
429
|
-
...options,
|
|
430
|
-
code: AuthConfigErrorCodes.AUTH_CONFIG_NOT_FOUND,
|
|
431
|
-
possibleFixes: options.possibleFixes || [
|
|
432
|
-
"Check if the auth config exists",
|
|
433
|
-
"Check if the auth config id is correct",
|
|
434
|
-
"Check if the auth config is enabled"
|
|
435
|
-
]
|
|
436
|
-
});
|
|
437
|
-
this.name = "ComposioAuthConfigNotFoundError";
|
|
438
|
-
}
|
|
439
|
-
};
|
|
440
|
-
|
|
441
|
-
//#endregion
|
|
442
|
-
//#region src/errors/ConnectionRequestErrors.ts
|
|
443
|
-
const ConnectionRequestErrorCodes = {
|
|
444
|
-
CONNECTION_REQUEST_TIMEOUT: "CONNECTION_REQUEST_TIMEOUT",
|
|
445
|
-
CONNECTION_REQUEST_FAILED: "CONNECTION_REQUEST_FAILED"
|
|
446
|
-
};
|
|
447
|
-
var ConnectionRequestTimeoutError = class extends ComposioError$1 {
|
|
448
|
-
constructor(message = "Connection request timed out", options = {}) {
|
|
449
|
-
super(message, {
|
|
450
|
-
...options,
|
|
451
|
-
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_TIMEOUT
|
|
452
|
-
});
|
|
453
|
-
this.name = "ConnectionRequestTimeoutError";
|
|
454
|
-
}
|
|
455
|
-
};
|
|
456
|
-
var ConnectionRequestFailedError = class extends ComposioError$1 {
|
|
457
|
-
constructor(message = "Connection request failed", options = {}) {
|
|
458
|
-
super(message, {
|
|
459
|
-
...options,
|
|
460
|
-
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_FAILED
|
|
461
|
-
});
|
|
462
|
-
this.name = "ConnectionRequestFailedError";
|
|
463
|
-
}
|
|
464
|
-
};
|
|
465
|
-
|
|
466
|
-
//#endregion
|
|
467
|
-
//#region src/errors/ToolkitErrors.ts
|
|
468
|
-
const ToolkitErrorCodes = { TOOLKIT_NOT_FOUND: "TOOLKIT_NOT_FOUND" };
|
|
469
|
-
var ComposioToolkitNotFoundError = class extends ComposioError$1 {
|
|
470
|
-
constructor(message = "Toolkit not found", options = {}) {
|
|
471
|
-
super(message, {
|
|
472
|
-
...options,
|
|
473
|
-
code: "TOOLKIT_NOT_FOUND",
|
|
474
|
-
possibleFixes: options.possibleFixes || ["Ensure the toolkit is correctly configured and the slug is valid"]
|
|
475
|
-
});
|
|
476
|
-
this.name = "ComposioToolkitNotFoundError";
|
|
477
|
-
}
|
|
478
|
-
};
|
|
479
|
-
var ComposioToolkitFetchError = class extends ComposioError$1 {
|
|
480
|
-
constructor(message = "Failed to fetch toolkit", options = {}) {
|
|
481
|
-
super(message, {
|
|
482
|
-
...options,
|
|
483
|
-
code: "TOOLKIT_FETCH_ERROR",
|
|
484
|
-
possibleFixes: options.possibleFixes || [
|
|
485
|
-
"Ensure the toolkit slug is valid",
|
|
486
|
-
"Ensure you are using the correct API key",
|
|
487
|
-
"Ensure you are using the correct API endpoint / Base URL and it is working"
|
|
488
|
-
]
|
|
489
|
-
});
|
|
490
|
-
this.name = "ComposioToolkitFetchError";
|
|
491
|
-
}
|
|
492
|
-
};
|
|
493
|
-
|
|
494
494
|
//#endregion
|
|
495
495
|
//#region src/errors/TriggerErrors.ts
|
|
496
496
|
const TriggerErrorCodes = {
|
|
@@ -614,4 +614,4 @@ var RemoteFileDownloadError = class extends ComposioError$1 {
|
|
|
614
614
|
};
|
|
615
615
|
|
|
616
616
|
//#endregion
|
|
617
|
-
export {
|
|
617
|
+
export { ToolErrorCodes as A, ComposioSharedAccessDeniedError as B, ComposioInvalidExecuteFunctionError as C, ComposioToolExecutionError as D, ComposioProviderNotDefinedError as E, ComposioAclOnlyForSharedError as F, ConnectedAccountErrorCodes as H, ComposioConnectedAccountNotFoundError as I, ComposioFailedToCreateConnectedAccountLink as L, ConnectionRequestErrorCodes as M, ConnectionRequestFailedError as N, ComposioToolNotFoundError as O, ConnectionRequestTimeoutError as P, ComposioLegacyConnectedAccountsEndpointRetiredError as R, ComposioGlobalExecuteToolFnNotSetError as S, ComposioInvalidToolArgumentsError as T, AuthConfigErrorCodes as U, ComposioSharedConnectionNotAccessibleError as V, ComposioAuthConfigNotFoundError as W, ValidationError as _, ComposioFailedToSubscribeToPusherChannelError as a, ComposioToolkitNotFoundError as b, ComposioWebhookPayloadError as c, ComposioNoAPIKeyError as d, ComposioRequestCancelledError as f, JsonSchemaToZodError as g, JsonSchemaRefResolutionError as h, ComposioFailedToGetSDKRealtimeCredentialsError as i, handleToolExecutionError as j, ComposioToolVersionRequiredError as k, ComposioWebhookSignatureVerificationError as l, isRequestAbortError as m, RemoteFileErrorCodes as n, ComposioFailedToUnsubscribeFromPusherChannelError as o, SDKErrorCodes as p, ComposioFailedToCreatePusherClientError as r, ComposioTriggerTypeNotFoundError as s, RemoteFileDownloadError as t, TriggerErrorCodes as u, ValidationErrorCodes as v, ComposioInvalidModifierError as w, ToolkitErrorCodes as x, ComposioToolkitFetchError as y, ComposioMultipleConnectedAccountsError as z };
|
|
@@ -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-
|
|
2
|
-
import { n as createCustomToolkit, t as createCustomTool } from "../CustomTool-
|
|
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";
|
|
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-
|
|
1
|
+
import { a as createCustomToolkit, i as createCustomTool } from "../CustomTool-C_5NvBsX.mjs";
|
|
2
2
|
|
|
3
3
|
export { createCustomTool as experimental_createTool, createCustomToolkit as experimental_createToolkit };
|
|
@@ -1,69 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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";
|
|
3
3
|
import { platform } from "#platform";
|
|
4
4
|
import fs from "node:fs";
|
|
5
5
|
import * as path from "node:path";
|
|
6
6
|
import crypto from "node:crypto";
|
|
7
|
+
import { lookup } from "node:dns/promises";
|
|
8
|
+
import { isIP } from "node:net";
|
|
7
9
|
|
|
8
|
-
//#region src/utils/sensitiveFileUploadPaths.node.ts
|
|
9
|
-
/**
|
|
10
|
-
* Blocks accidental upload of local files from well-known secret/credential locations
|
|
11
|
-
* during auto file upload (and {@link getFileDataAfterUploadingToS3}).
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* Path segments (a single path component) that indicate a sensitive directory when
|
|
15
|
-
* they appear anywhere in a resolved local path. Compared case-insensitively on Windows.
|
|
16
|
-
*/
|
|
17
|
-
const BUILTIN_FILE_UPLOAD_PATH_DENY_SEGMENTS = [
|
|
18
|
-
".ssh",
|
|
19
|
-
".aws",
|
|
20
|
-
".azure",
|
|
21
|
-
".gnupg",
|
|
22
|
-
".kube",
|
|
23
|
-
".docker",
|
|
24
|
-
".claude",
|
|
25
|
-
".password-store",
|
|
26
|
-
"keychains"
|
|
27
|
-
];
|
|
28
|
-
const SECRET_LIKE_BASENAME = /^(\.env(\.|$)|\.netrc$|\.pgpass$)/i;
|
|
29
|
-
/** Default SSH private key basenames (public keys like id_rsa.pub are allowed). */
|
|
30
|
-
const DEFAULT_PRIVATE_KEY_BASENAME = /^id_(rsa|ed25519|ecdsa|dsa|ecdsa_sk)(\.old)?$/i;
|
|
31
|
-
/**
|
|
32
|
-
* Returns normalized path segments, resolving symlinks when the path exists.
|
|
33
|
-
*/
|
|
34
|
-
function normalizePathSegments(filePath) {
|
|
35
|
-
const absolute = path.resolve(filePath);
|
|
36
|
-
let resolved = absolute;
|
|
37
|
-
try {
|
|
38
|
-
if (fs.existsSync(absolute)) resolved = fs.realpathSync(absolute);
|
|
39
|
-
} catch {}
|
|
40
|
-
return resolved.split(/[/\\]+/).filter(Boolean);
|
|
41
|
-
}
|
|
42
|
-
function getSensitiveFileUploadPathBlockReason(filePath, additionalDenySegments) {
|
|
43
|
-
const segments = normalizePathSegments(filePath);
|
|
44
|
-
const isWin = process.platform === "win32";
|
|
45
|
-
const deny = new Set([...BUILTIN_FILE_UPLOAD_PATH_DENY_SEGMENTS, ...(additionalDenySegments ?? []).map((s) => s.trim()).filter(Boolean)].map((s) => isWin ? s.toLowerCase() : s));
|
|
46
|
-
const segmentsForMatch = isWin ? segments.map((s) => s.toLowerCase()) : segments;
|
|
47
|
-
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`;
|
|
48
|
-
const basename = segments.length > 0 ? segments[segments.length - 1] : "";
|
|
49
|
-
if (basename) {
|
|
50
|
-
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`;
|
|
51
|
-
if (basename.toLowerCase() === "credentials") return "file name \"credentials\" is often used for cloud/API credential stores";
|
|
52
|
-
}
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* @throws {ComposioSensitiveFilePathBlockedError} if the path is not allowed
|
|
57
|
-
*/
|
|
58
|
-
function assertSafeFileUploadPath(filePath, options) {
|
|
59
|
-
const reason = getSensitiveFileUploadPathBlockReason(filePath, options?.additionalDenySegments);
|
|
60
|
-
if (reason) throw new ComposioSensitiveFilePathBlockedError(`Refusing to upload: ${reason}. To upload from this path anyway, set sensitiveFileUploadProtection: false on Composio (not recommended) or use a copy outside sensitive locations.`, { meta: {
|
|
61
|
-
filePath,
|
|
62
|
-
reason
|
|
63
|
-
} });
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
//#endregion
|
|
67
10
|
//#region src/utils/uploadDirAllowlist.node.ts
|
|
68
11
|
/**
|
|
69
12
|
* Allowlist for automatic file upload during tool execution.
|
|
@@ -208,8 +151,173 @@ function assertPathInsideUploadDirs(filePath, allowlist) {
|
|
|
208
151
|
} });
|
|
209
152
|
}
|
|
210
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
|
+
|
|
211
301
|
//#endregion
|
|
212
302
|
//#region src/utils/fileUtils.node.ts
|
|
303
|
+
/**
|
|
304
|
+
* Checks whether `value` is an absolute http(s) URL rather than a local path.
|
|
305
|
+
*
|
|
306
|
+
* A bare `startsWith('http')` check also matches local paths like
|
|
307
|
+
* `http_export/report.csv` or `httpdocs/.env`, which routes them into the URL
|
|
308
|
+
* fetch branch and skips the allowlist/denylist checks in
|
|
309
|
+
* {@link getFileDataAfterUploadingToS3}. `new URL()` requires a real scheme
|
|
310
|
+
* (`http:` or `https:`) followed by `//`, so relative-looking paths correctly
|
|
311
|
+
* fail to parse and are treated as local.
|
|
312
|
+
*/
|
|
313
|
+
const isHttpUrl = (value) => {
|
|
314
|
+
try {
|
|
315
|
+
const url = new URL(value);
|
|
316
|
+
return url.protocol === "http:" || url.protocol === "https:";
|
|
317
|
+
} catch {
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
};
|
|
213
321
|
const getExtensionFromMimeType = (mimeType) => {
|
|
214
322
|
const mimeToExt = {
|
|
215
323
|
"text/plain": "txt",
|
|
@@ -290,15 +398,20 @@ const readFileContent = async (filePath) => {
|
|
|
290
398
|
}
|
|
291
399
|
};
|
|
292
400
|
const readFileContentFromURL = async (path, signal) => {
|
|
293
|
-
const response = await
|
|
401
|
+
const response = await ssrfSafeFetch(path, { signal });
|
|
294
402
|
if (!response.ok) throw new Error(`Failed to fetch file: ${response.statusText}`);
|
|
295
403
|
const arrayBuffer = await response.arrayBuffer();
|
|
296
404
|
const content = new Uint8Array(arrayBuffer);
|
|
297
405
|
const mimeType = response.headers.get("content-type") || "application/octet-stream";
|
|
298
406
|
const pathname = new URL(path).pathname;
|
|
299
407
|
let fileName = platform.basename(pathname);
|
|
300
|
-
if (!fileName || fileName === "/")
|
|
301
|
-
|
|
408
|
+
if (!fileName || fileName === "/") {
|
|
409
|
+
const extension = getExtensionFromMimeType(mimeType);
|
|
410
|
+
fileName = generateTimestampedFilename(extension);
|
|
411
|
+
} else if (!fileName.includes(".")) {
|
|
412
|
+
const extension = getExtensionFromMimeType(mimeType);
|
|
413
|
+
fileName = generateTimestampedFilename(extension);
|
|
414
|
+
}
|
|
302
415
|
return {
|
|
303
416
|
content: uint8ArrayToBase64(content),
|
|
304
417
|
mimeType,
|
|
@@ -334,13 +447,13 @@ const readFile = async (file, signal) => {
|
|
|
334
447
|
content: uint8ArrayToBase64(new Uint8Array(content)),
|
|
335
448
|
mimeType: file.type
|
|
336
449
|
};
|
|
337
|
-
} else if (typeof file === "string") if (file
|
|
450
|
+
} else if (typeof file === "string") if (isHttpUrl(file)) return await readFileContentFromURL(file, signal);
|
|
338
451
|
else return await readFileContent(file);
|
|
339
452
|
throw new Error("Invalid file type");
|
|
340
453
|
};
|
|
341
454
|
const getFileDataAfterUploadingToS3 = async (file, { toolSlug, toolkitSlug, client, sensitiveFileUploadProtection, fileUploadPathDenySegments, fileUploadAllowlist, signal }) => {
|
|
342
455
|
if (!file) throw new Error("Either path or blob must be provided");
|
|
343
|
-
const isLocalPath = typeof file === "string" && !file
|
|
456
|
+
const isLocalPath = typeof file === "string" && !isHttpUrl(file);
|
|
344
457
|
if (isLocalPath && fileUploadAllowlist !== void 0) assertPathInsideUploadDirs(file, fileUploadAllowlist);
|
|
345
458
|
if (sensitiveFileUploadProtection !== false && isLocalPath) assertSafeFileUploadPath(file, { additionalDenySegments: fileUploadPathDenySegments });
|
|
346
459
|
const fileData = await readFile(file, signal);
|
|
@@ -357,7 +470,8 @@ const downloadFileFromS3 = async ({ toolSlug, s3Url, mimeType, fileDownloadDir,
|
|
|
357
470
|
const response = await fetch(s3Url, { signal });
|
|
358
471
|
if (!response.ok) throw new Error(`Failed to download file: ${response.statusText}`);
|
|
359
472
|
const data = await response.arrayBuffer();
|
|
360
|
-
const
|
|
473
|
+
const extension = getExtensionFromMimeType(mimeType);
|
|
474
|
+
const fileName = generateTimestampedFilename(extension, `${toolSlug}_`);
|
|
361
475
|
return {
|
|
362
476
|
name: fileName,
|
|
363
477
|
mimeType,
|
|
@@ -445,4 +559,4 @@ const saveFile = (file, content, options = {}) => {
|
|
|
445
559
|
};
|
|
446
560
|
|
|
447
561
|
//#endregion
|
|
448
|
-
export { getFileDataAfterUploadingToS3 as n, downloadFileFromS3 as t };
|
|
562
|
+
export { getFileDataAfterUploadingToS3 as n, isHttpUrl as r, downloadFileFromS3 as t };
|