@composio/core 1.0.0-beta.0 → 1.0.0-beta.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-CM-roKk7.mjs} +16 -6
- package/dist/{CustomTool-CwpeQhz2.d.mts → CustomTool-yMQjEyMz.d.mts} +1 -1
- package/dist/{FileModifierErrors-B8V8_3VE.mjs → FileModifierErrors-CdGSABoq.mjs} +1 -1
- package/dist/{FileToolModifier.utils.neutral-D_YkHwZP.mjs → FileToolModifier.utils.neutral-DWFpnsj2.mjs} +4 -2
- package/dist/{SsrfErrors-DNJt57GL.mjs → SsrfErrors-DiQldIdC.mjs} +154 -19
- package/dist/{Telemetry-DK1uAWnD.mjs → Telemetry-JRJJYS4I.mjs} +28 -44
- package/dist/cancellation-BEpFk2S8.mjs +706 -0
- package/dist/{composio-XjF7EMEe.d.mts → composio-BVNJTVYa.d.mts} +2450 -119
- package/dist/{customTool.types-DpJbYY5m.d.mts → customTool.types-CY5SXFfF.d.mts} +143 -28
- 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-CvZjP9CH.mjs} +42 -4
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/{fileUtils.node-BwpUOF0s.mjs → fileUtils.node-HQsywtTj.mjs} +11 -9
- package/dist/index.d.mts +393 -142
- package/dist/index.mjs +1945 -171
- package/dist/models/Files.node.d.mts +2 -3
- package/dist/models/Files.node.mjs +2 -2
- package/dist/models/Files.workerd.d.mts +2 -3
- package/dist/platform/node.d.mts +2 -3
- package/dist/platform/workerd.d.mts +2 -3
- package/dist/{sensitiveFileUploadPaths-B0w8dqpv.mjs → sensitiveFileUploadPaths-BlLp-Yo2.mjs} +10 -7
- package/dist/{ssrfGuard.node-DlxO8uzr.mjs → ssrfGuard.node-BK50mYTq.mjs} +187 -24
- package/dist/{types-C9kJAurw.d.mts → types-CqGfjlZg.d.mts} +2 -2
- package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +3 -4
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +3 -4
- package/dist/utils/modifiers/FileToolModifier.node.d.mts +3 -4
- package/dist/utils/modifiers/FileToolModifier.node.mjs +6 -6
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +3 -4
- package/dist/utils/modifiers/FileToolModifier.workerd.mjs +1 -1
- package/dist/utils/ssrfGuard.node.d.mts +7 -7
- package/dist/utils/ssrfGuard.node.mjs +1 -1
- package/dist/utils/ssrfGuard.workerd.d.mts +3 -4
- package/dist/utils/ssrfGuard.workerd.mjs +2 -2
- package/package.json +25 -7
- package/src/composio.ts +86 -2
- package/src/errors/ConnectedAccountsErrors.ts +47 -0
- package/src/errors/ToolErrors.ts +1 -0
- package/src/errors/ValidationErrors.ts +2 -0
- package/src/index.ts +21 -0
- package/src/models/ConnectedAccounts.ts +118 -2
- package/src/models/CustomTool.ts +41 -6
- package/src/models/CustomToolkits.ts +169 -0
- package/src/models/Experimental.ts +27 -0
- package/src/models/Keyring.ts +65 -0
- package/src/models/Logs.ts +101 -0
- package/src/models/RemoteFile.ts +54 -36
- package/src/models/ToolRouterSession.ts +60 -4
- package/src/models/Toolkits.ts +180 -0
- package/src/models/Tools.ts +3 -1
- package/src/models/Triggers.ts +17 -87
- package/src/models/Usage.ts +119 -0
- package/src/models/Webhooks.ts +520 -0
- package/src/services/telemetry/TelemetryService.ts +27 -12
- package/src/telemetry/redact.ts +133 -6
- package/src/types/authConfigs.types.ts +2 -0
- package/src/types/connectedAccounts.types.ts +54 -0
- package/src/types/customToolkits.types.ts +102 -0
- package/src/types/keyring.types.ts +32 -0
- package/src/types/logs.types.ts +108 -0
- package/src/types/toolRouter.types.ts +49 -1
- package/src/types/toolkit.types.ts +131 -0
- package/src/types/usage.types.ts +81 -0
- package/src/types/webhooks.types.ts +143 -0
- package/src/utils/constants.ts +1 -5
- package/src/utils/fileUtils.node.ts +10 -2
- package/src/utils/jsonSchema.ts +509 -28
- package/src/utils/logger.ts +45 -13
- package/src/utils/pinnedDispatcher.node.ts +109 -13
- package/src/utils/sdk.ts +1 -1
- package/src/utils/ssrfGuard.node.ts +124 -21
- package/src/utils/ssrfGuard.workerd.ts +5 -1
- package/src/utils/transformers/connectedAccounts.ts +37 -2
- package/src/utils/transformers/customToolkits.ts +98 -0
- package/src/utils/transformers/keyring.ts +24 -0
- package/src/utils/transformers/logs.ts +85 -0
- package/src/utils/transformers/toolkits.ts +100 -1
- package/src/utils/transformers/triggers.ts +2 -2
- package/src/utils/transformers/usage.ts +77 -0
- package/src/utils/transformers/webhooks.ts +139 -0
- package/dist/cancellation-C-qy8rcj.mjs +0 -364
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { isIP } from 'node:net';
|
|
2
|
+
import { request as httpRequest } from 'node:http';
|
|
3
|
+
import { request as httpsRequest } from 'node:https';
|
|
4
|
+
import { Readable } from 'node:stream';
|
|
2
5
|
import type { Agent } from 'undici';
|
|
3
6
|
|
|
4
7
|
/**
|
|
@@ -36,6 +39,37 @@ const GLOBAL_DISPATCHER_SYMBOLS = [
|
|
|
36
39
|
let undici: Promise<typeof import('undici')> | undefined;
|
|
37
40
|
const loadUndici = (): Promise<typeof import('undici')> => (undici ??= import('undici'));
|
|
38
41
|
|
|
42
|
+
const lookupPinnedAddresses = (
|
|
43
|
+
addresses: ReadonlyArray<string>,
|
|
44
|
+
options: { all?: boolean },
|
|
45
|
+
callback: (
|
|
46
|
+
error: NodeJS.ErrnoException | null,
|
|
47
|
+
address: string | Array<{ address: string; family: number }>,
|
|
48
|
+
family?: number
|
|
49
|
+
) => void
|
|
50
|
+
) => {
|
|
51
|
+
if (options.all) {
|
|
52
|
+
callback(
|
|
53
|
+
null,
|
|
54
|
+
addresses.map(address => ({ address, family: isIP(address) }))
|
|
55
|
+
);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const [address] = addresses;
|
|
60
|
+
callback(null, address, isIP(address));
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const knownBodyLength = (body: BodyInit | null | undefined): number | undefined => {
|
|
64
|
+
if (body === null || body === undefined) return undefined;
|
|
65
|
+
if (typeof body === 'string') return new TextEncoder().encode(body).byteLength;
|
|
66
|
+
if (body instanceof URLSearchParams) return new TextEncoder().encode(body.toString()).byteLength;
|
|
67
|
+
if (body instanceof ArrayBuffer) return body.byteLength;
|
|
68
|
+
if (ArrayBuffer.isView(body)) return body.byteLength;
|
|
69
|
+
if (body instanceof Blob) return body.size;
|
|
70
|
+
return undefined;
|
|
71
|
+
};
|
|
72
|
+
|
|
39
73
|
/**
|
|
40
74
|
* A `fetch` dispatcher that connects to `addresses` instead of resolving the
|
|
41
75
|
* hostname again.
|
|
@@ -71,24 +105,86 @@ export const createPinnedDispatcher = async (addresses: ReadonlyArray<string>):
|
|
|
71
105
|
// off, or a `family`/`localAddress` was requested. Answering in the
|
|
72
106
|
// wrong shape is rejected as an invalid address, which would fail
|
|
73
107
|
// every pinned fetch in such a process.
|
|
74
|
-
|
|
75
|
-
// All of them, in resolver order: handing over a single address of a
|
|
76
|
-
// dual-stack host would strand callers whose network cannot reach
|
|
77
|
-
// that family, where the runtime would otherwise have fallen back.
|
|
78
|
-
callback(
|
|
79
|
-
null,
|
|
80
|
-
addresses.map(address => ({ address, family: isIP(address) }))
|
|
81
|
-
);
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const [address] = addresses;
|
|
86
|
-
callback(null, address, isIP(address));
|
|
108
|
+
lookupPinnedAddresses(addresses, options, callback);
|
|
87
109
|
},
|
|
88
110
|
},
|
|
89
111
|
});
|
|
90
112
|
};
|
|
91
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Fetch through the Node-compatible HTTP client while pinning DNS resolution.
|
|
116
|
+
*
|
|
117
|
+
* Bun implements the Node HTTP client and its `lookup` hook, but its native
|
|
118
|
+
* `fetch` ignores undici's `dispatcher` option. This transport preserves the
|
|
119
|
+
* original hostname for Host and TLS SNI while making the socket use an
|
|
120
|
+
* address that the SSRF guard already validated.
|
|
121
|
+
*/
|
|
122
|
+
export const pinnedHttpFetch = async (
|
|
123
|
+
rawUrl: string,
|
|
124
|
+
init: RequestInit,
|
|
125
|
+
addresses: ReadonlyArray<string>
|
|
126
|
+
): Promise<Response> => {
|
|
127
|
+
const normalized = new Request(rawUrl, init);
|
|
128
|
+
const url = new URL(rawUrl);
|
|
129
|
+
const request = url.protocol === 'https:' ? httpsRequest : httpRequest;
|
|
130
|
+
const headers = new Headers(normalized.headers);
|
|
131
|
+
const bodyLength = knownBodyLength(init.body);
|
|
132
|
+
if (bodyLength !== undefined && !headers.has('content-length')) {
|
|
133
|
+
headers.set('content-length', String(bodyLength));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return new Promise<Response>((resolve, reject) => {
|
|
137
|
+
const outgoing = request(
|
|
138
|
+
url,
|
|
139
|
+
{
|
|
140
|
+
method: normalized.method,
|
|
141
|
+
headers: Object.fromEntries(headers.entries()),
|
|
142
|
+
signal: normalized.signal,
|
|
143
|
+
lookup: (_hostname, options, callback) =>
|
|
144
|
+
lookupPinnedAddresses(addresses, options, callback),
|
|
145
|
+
},
|
|
146
|
+
incoming => {
|
|
147
|
+
const headers = new Headers();
|
|
148
|
+
for (let index = 0; index < incoming.rawHeaders.length; index += 2) {
|
|
149
|
+
headers.append(incoming.rawHeaders[index], incoming.rawHeaders[index + 1]);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const status = incoming.statusCode ?? 500;
|
|
153
|
+
const body = [101, 103, 204, 205, 304].includes(status)
|
|
154
|
+
? null
|
|
155
|
+
: (Readable.toWeb(incoming) as ReadableStream<Uint8Array>);
|
|
156
|
+
resolve(
|
|
157
|
+
new Response(body, {
|
|
158
|
+
status,
|
|
159
|
+
statusText: incoming.statusMessage,
|
|
160
|
+
headers,
|
|
161
|
+
})
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
outgoing.once('error', reject);
|
|
167
|
+
|
|
168
|
+
void (async () => {
|
|
169
|
+
try {
|
|
170
|
+
if (normalized.body) {
|
|
171
|
+
const reader = normalized.body.getReader();
|
|
172
|
+
while (true) {
|
|
173
|
+
const { done, value } = await reader.read();
|
|
174
|
+
if (done) break;
|
|
175
|
+
if (!outgoing.write(value)) {
|
|
176
|
+
await new Promise<void>(resolveDrain => outgoing.once('drain', resolveDrain));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
outgoing.end();
|
|
181
|
+
} catch (error) {
|
|
182
|
+
outgoing.destroy(error instanceof Error ? error : new Error(String(error)));
|
|
183
|
+
}
|
|
184
|
+
})();
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
|
|
92
188
|
/**
|
|
93
189
|
* Whether the process-wide dispatcher `fetch` falls back to (when a request
|
|
94
190
|
* carries no `dispatcher` of its own) is something other than a stock `Agent`.
|
package/src/utils/sdk.ts
CHANGED
|
@@ -53,7 +53,7 @@ export function getSDKConfig(baseUrl?: string | null, apiKey?: string | null) {
|
|
|
53
53
|
ComposioError.handleAndThrow(new ComposioNoAPIKeyError());
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
logger.debug('Environment',
|
|
56
|
+
logger.debug('Environment', 'API Key: [REDACTED]');
|
|
57
57
|
logger.debug('Environment', `Base URL: ${baseURLParsed}`);
|
|
58
58
|
|
|
59
59
|
return { baseURL: baseURLParsed, apiKey: apiKeyParsed };
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { lookup } from 'node:dns/promises'; // we're in a Node.js-specific module
|
|
2
2
|
import { isIP } from 'node:net';
|
|
3
3
|
import { ComposioBlockedInternalUrlError } from '../errors/SsrfErrors';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
createPinnedDispatcher,
|
|
6
|
+
hasCustomGlobalDispatcher,
|
|
7
|
+
pinnedHttpFetch,
|
|
8
|
+
} from './pinnedDispatcher.node';
|
|
5
9
|
|
|
6
10
|
/**
|
|
7
11
|
* SSRF guard for user-supplied URL file inputs.
|
|
@@ -26,7 +30,8 @@ import { createPinnedDispatcher, hasCustomGlobalDispatcher } from './pinnedDispa
|
|
|
26
30
|
* Residual: a hop whose effective dispatcher is a configured route — a
|
|
27
31
|
* caller-supplied `init.dispatcher`, a non-stock global dispatcher (a
|
|
28
32
|
* `ProxyAgent` or `EnvHttpProxyAgent` installed via `setGlobalDispatcher`), or
|
|
29
|
-
* the runtime's env-proxy mode (
|
|
33
|
+
* the runtime's env-proxy mode (automatic on Bun, opt-in via
|
|
34
|
+
* `NODE_USE_ENV_PROXY` on Node) — keeps only the
|
|
30
35
|
* pre-flight validation. Pinning would dial the validated address instead of
|
|
31
36
|
* the proxy, and the proxy resolves the hostname itself where the SDK cannot
|
|
32
37
|
* see or pin that resolution. The Python guard carries the same residual for
|
|
@@ -35,19 +40,88 @@ import { createPinnedDispatcher, hasCustomGlobalDispatcher } from './pinnedDispa
|
|
|
35
40
|
|
|
36
41
|
const MAX_REDIRECTS = 5;
|
|
37
42
|
|
|
43
|
+
/**
|
|
44
|
+
* The Fetch standard's "redirect status" set. A 3xx outside it is not a
|
|
45
|
+
* redirect to follow even when it carries a `location` — `304 Not Modified`
|
|
46
|
+
* and `305 Use Proxy` most of all, and following those would replay the
|
|
47
|
+
* request against a target the caller never asked for. The Python guard
|
|
48
|
+
* follows the same set (`_REDIRECT_STATUS_CODES`).
|
|
49
|
+
*/
|
|
50
|
+
const REDIRECT_STATUS_CODES = new Set([301, 302, 303, 307, 308]);
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Headers that describe a request body, so they have to go when the body does:
|
|
54
|
+
* the Fetch standard's "request-body-header name" set, plus the two the Python
|
|
55
|
+
* guard also drops because `requests` recomputes them from the body it sends.
|
|
56
|
+
*/
|
|
57
|
+
const BODY_HEADERS = [
|
|
58
|
+
'content-encoding',
|
|
59
|
+
'content-language',
|
|
60
|
+
'content-length',
|
|
61
|
+
'content-location',
|
|
62
|
+
'content-type',
|
|
63
|
+
'transfer-encoding',
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The method the hop after a redirect uses, or `null` to replay as-is. A
|
|
68
|
+
* returned method also means the request body goes.
|
|
69
|
+
*
|
|
70
|
+
* These are the Fetch standard's redirect rules, which following redirects by
|
|
71
|
+
* hand (`redirect: 'manual'`) means `fetch` never applies for us: `303` points
|
|
72
|
+
* at a result URL that has no use for the original body, so every method loses
|
|
73
|
+
* it and everything but `HEAD` becomes a `GET`; `301`/`302` do the same to a
|
|
74
|
+
* `POST` only; `307`/`308` replay both. Without this, a `303` answering an
|
|
75
|
+
* upload would PUT the payload again at a URL that expects a GET. The Python
|
|
76
|
+
* guard applies the same rules in `safe_request`.
|
|
77
|
+
*/
|
|
78
|
+
const redirectRewrite = (status: number, method: string): string | null => {
|
|
79
|
+
if (status === 303) return method === 'HEAD' ? 'HEAD' : 'GET';
|
|
80
|
+
if ((status === 301 || status === 302) && method === 'POST') return 'GET';
|
|
81
|
+
return null;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Headers that carry a credential for the origin the request was addressed
|
|
86
|
+
* to, so they must not follow a redirect to a different origin. The Fetch
|
|
87
|
+
* standard strips `Authorization` on a cross-origin redirect; `Cookie` and
|
|
88
|
+
* `Proxy-Authorization` go with it the way `requests` and curl drop them on a
|
|
89
|
+
* host change. `redirect: 'manual'` means `fetch` never applies that rule for
|
|
90
|
+
* us either. The Python guard drops the same three (`_CREDENTIAL_HEADERS`).
|
|
91
|
+
*/
|
|
92
|
+
const CREDENTIAL_HEADERS = ['authorization', 'cookie', 'proxy-authorization'];
|
|
93
|
+
|
|
94
|
+
const applyRedirectSemantics = (
|
|
95
|
+
init: RequestInit,
|
|
96
|
+
status: number,
|
|
97
|
+
fromUrl: string,
|
|
98
|
+
toUrl: string
|
|
99
|
+
): RequestInit => {
|
|
100
|
+
const method = redirectRewrite(status, (init.method ?? 'GET').toUpperCase());
|
|
101
|
+
const crossOrigin = new URL(fromUrl).origin !== new URL(toUrl).origin;
|
|
102
|
+
if (method === null && !crossOrigin) return init;
|
|
103
|
+
|
|
104
|
+
const headers = new Headers(init.headers);
|
|
105
|
+
if (method !== null) for (const name of BODY_HEADERS) headers.delete(name);
|
|
106
|
+
if (crossOrigin) for (const name of CREDENTIAL_HEADERS) headers.delete(name);
|
|
107
|
+
if (method === null) return { ...init, headers };
|
|
108
|
+
return { ...init, method, body: undefined, headers };
|
|
109
|
+
};
|
|
110
|
+
|
|
38
111
|
/**
|
|
39
112
|
* Whether the runtime would route `url` through an env proxy the SDK cannot
|
|
40
|
-
* see into.
|
|
41
|
-
* `fetch`
|
|
42
|
-
*
|
|
43
|
-
*
|
|
113
|
+
* see into. Bun honors proxy environment variables automatically. Node's
|
|
114
|
+
* built-in `fetch` requires the `NODE_USE_ENV_PROXY` opt-in (Node >= 24), so
|
|
115
|
+
* a bare env-var check on Node would drop pinning for users whose fetch never
|
|
116
|
+
* proxied.
|
|
44
117
|
*
|
|
45
118
|
* `NO_PROXY=*` is the one bypass honored precisely (nothing is proxied, so
|
|
46
119
|
* pinning is safe again); per-host `NO_PROXY` entries are treated
|
|
47
120
|
* conservatively as proxied rather than parsed.
|
|
48
121
|
*/
|
|
49
|
-
const envProxyApplies = (url: URL): boolean => {
|
|
50
|
-
const useEnvProxy =
|
|
122
|
+
const envProxyApplies = (url: URL, isBun: boolean): boolean => {
|
|
123
|
+
const useEnvProxy =
|
|
124
|
+
isBun || ['1', 'true'].includes((process.env.NODE_USE_ENV_PROXY ?? '').toLowerCase());
|
|
51
125
|
if (!useEnvProxy) return false;
|
|
52
126
|
if ((process.env.NO_PROXY ?? process.env.no_proxy ?? '') === '*') return false;
|
|
53
127
|
const schemeVar = url.protocol === 'https:' ? 'HTTPS_PROXY' : 'HTTP_PROXY';
|
|
@@ -71,6 +145,7 @@ const IPV4_BLOCKED_CIDRS: ReadonlyArray<readonly [string, number]> = [
|
|
|
71
145
|
['172.16.0.0', 12], // private
|
|
72
146
|
['192.0.0.0', 24], // IETF protocol assignments
|
|
73
147
|
['192.0.2.0', 24], // TEST-NET-1
|
|
148
|
+
['192.88.99.0', 24], // 6to4 relay anycast (deprecated, RFC 7526)
|
|
74
149
|
['192.168.0.0', 16], // private
|
|
75
150
|
['198.18.0.0', 15], // benchmarking
|
|
76
151
|
['198.51.100.0', 24], // TEST-NET-2
|
|
@@ -140,8 +215,20 @@ const isBlockedIpv6 = (ip: string): boolean => {
|
|
|
140
215
|
return isBlockedIpv4Long((((h[6] << 16) >>> 0) | h[7]) >>> 0);
|
|
141
216
|
}
|
|
142
217
|
|
|
218
|
+
// Transition and tunnel ranges. Each one either carries an arbitrary IPv4
|
|
219
|
+
// address in its low bits or is reserved, so a public-looking literal here
|
|
220
|
+
// can still name internal space: `2002:7f00:1::` is 6to4 for `127.0.0.1`.
|
|
221
|
+
// Blocking the whole range rather than decoding it matches the Python guard,
|
|
222
|
+
// where `ipaddress.is_global` already rejects all of them.
|
|
223
|
+
if (h[0] === 0x2001 && (h[1] & 0xfe00) === 0) return true; // IETF protocol assignments 2001::/23 (incl. Teredo)
|
|
224
|
+
if (h[0] === 0x2001 && h[1] === 0x0db8) return true; // documentation 2001:db8::/32
|
|
225
|
+
if (h[0] === 0x2002) return true; // 6to4 2002::/16
|
|
226
|
+
if (h[0] === 0x0064 && h[1] === 0xff9b && h[2] === 0x0001) return true; // local-use NAT64 64:ff9b:1::/48
|
|
227
|
+
if (h[0] === 0x0100 && h[1] === 0 && h[2] === 0 && h[3] === 0) return true; // discard-only 100::/64
|
|
228
|
+
|
|
143
229
|
if ((h[0] & 0xfe00) === 0xfc00) return true; // unique local fc00::/7
|
|
144
230
|
if ((h[0] & 0xffc0) === 0xfe80) return true; // link-local fe80::/10
|
|
231
|
+
if ((h[0] & 0xffc0) === 0xfec0) return true; // site-local fec0::/10 (deprecated)
|
|
145
232
|
if ((h[0] & 0xff00) === 0xff00) return true; // multicast ff00::/8
|
|
146
233
|
|
|
147
234
|
return false;
|
|
@@ -215,7 +302,8 @@ export const assertSafeFetchTarget = async (rawUrl: string): Promise<string[]> =
|
|
|
215
302
|
* connects to the address it validated, and re-validates and re-pins every
|
|
216
303
|
* redirect hop (redirects are followed manually up to {@link MAX_REDIRECTS}).
|
|
217
304
|
* Intermediate redirect bodies are cancelled; non-redirect responses are
|
|
218
|
-
* returned unchanged.
|
|
305
|
+
* returned unchanged. Each hop carries the method, body, and credential headers
|
|
306
|
+
* the Fetch standard says it should — see {@link applyRedirectSemantics}.
|
|
219
307
|
*
|
|
220
308
|
* A hop whose effective dispatcher is a configured route (caller-supplied
|
|
221
309
|
* `init.dispatcher`, non-stock global dispatcher, env-proxy mode) is *not*
|
|
@@ -227,30 +315,43 @@ export const ssrfSafeFetch = async (
|
|
|
227
315
|
maxRedirects: number = MAX_REDIRECTS
|
|
228
316
|
): Promise<Response> => {
|
|
229
317
|
let currentUrl = rawUrl;
|
|
318
|
+
// Rebound per hop: a redirect can drop the method and body (see
|
|
319
|
+
// `applyRedirectSemantics`), and the following hops must send what is left.
|
|
320
|
+
let currentInit = init;
|
|
230
321
|
|
|
231
322
|
for (let hop = 0; hop <= maxRedirects; hop++) {
|
|
232
323
|
const addresses = await assertSafeFetchTarget(currentUrl);
|
|
324
|
+
const isBun = typeof process.versions.bun === 'string';
|
|
233
325
|
|
|
234
326
|
// Pinning replaces the connect target; through a configured route that
|
|
235
327
|
// would dial the validated origin instead of the route's next hop (the
|
|
236
328
|
// proxy), so those hops keep the pre-flight check only.
|
|
237
|
-
const callerDispatcher = (
|
|
329
|
+
const callerDispatcher = (currentInit as RequestInit & { dispatcher?: unknown }).dispatcher;
|
|
238
330
|
const respectConfiguredRoute =
|
|
239
331
|
callerDispatcher !== undefined ||
|
|
240
|
-
envProxyApplies(new URL(currentUrl)) ||
|
|
332
|
+
envProxyApplies(new URL(currentUrl), isBun) ||
|
|
241
333
|
hasCustomGlobalDispatcher();
|
|
242
334
|
|
|
243
|
-
const dispatcher =
|
|
335
|
+
const dispatcher =
|
|
336
|
+
respectConfiguredRoute || isBun ? undefined : await createPinnedDispatcher(addresses);
|
|
244
337
|
|
|
245
338
|
let response: Response;
|
|
246
339
|
try {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
340
|
+
if (isBun && !respectConfiguredRoute) {
|
|
341
|
+
response = await pinnedHttpFetch(
|
|
342
|
+
currentUrl,
|
|
343
|
+
{ ...currentInit, redirect: 'manual' },
|
|
344
|
+
addresses
|
|
345
|
+
);
|
|
346
|
+
} else {
|
|
347
|
+
// `dispatcher` is a Node-only extension to `RequestInit`.
|
|
348
|
+
response = await fetch(
|
|
349
|
+
currentUrl,
|
|
350
|
+
(dispatcher === undefined
|
|
351
|
+
? { ...currentInit, redirect: 'manual' }
|
|
352
|
+
: { ...currentInit, redirect: 'manual', dispatcher }) as RequestInit
|
|
353
|
+
);
|
|
354
|
+
}
|
|
254
355
|
} catch (error) {
|
|
255
356
|
if (dispatcher !== undefined) {
|
|
256
357
|
await dispatcher.close().catch(() => undefined);
|
|
@@ -265,7 +366,7 @@ export const ssrfSafeFetch = async (
|
|
|
265
366
|
}
|
|
266
367
|
|
|
267
368
|
const isRedirect =
|
|
268
|
-
|
|
369
|
+
REDIRECT_STATUS_CODES.has(response.status) && response.headers.has('location');
|
|
269
370
|
if (!isRedirect) {
|
|
270
371
|
return response;
|
|
271
372
|
}
|
|
@@ -274,7 +375,9 @@ export const ssrfSafeFetch = async (
|
|
|
274
375
|
// than leaving it to the garbage collector (mirrors `readResponseBodyWithLimit`).
|
|
275
376
|
await response.body?.cancel().catch(() => undefined);
|
|
276
377
|
|
|
277
|
-
|
|
378
|
+
const nextUrl = new URL(response.headers.get('location')!, currentUrl).toString();
|
|
379
|
+
currentInit = applyRedirectSemantics(currentInit, response.status, currentUrl, nextUrl);
|
|
380
|
+
currentUrl = nextUrl;
|
|
278
381
|
}
|
|
279
382
|
|
|
280
383
|
throw new ComposioBlockedInternalUrlError(
|
|
@@ -5,7 +5,11 @@ import { ComposioBlockedInternalUrlError } from '../errors/SsrfErrors';
|
|
|
5
5
|
* hostname is publicly routable before connecting. Fail closed instead of
|
|
6
6
|
* falling back to an unguarded fetch.
|
|
7
7
|
*/
|
|
8
|
-
export const ssrfSafeFetch = async (
|
|
8
|
+
export const ssrfSafeFetch = async (
|
|
9
|
+
rawUrl: string,
|
|
10
|
+
_init: RequestInit = {},
|
|
11
|
+
_maxRedirects?: number
|
|
12
|
+
): Promise<Response> => {
|
|
9
13
|
throw new ComposioBlockedInternalUrlError(
|
|
10
14
|
'URL file uploads are not supported in edge runtimes because the destination cannot be safely validated',
|
|
11
15
|
{
|
|
@@ -1,20 +1,30 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ConnectedAccountListResponse as RawConnectedAccountListResponse,
|
|
3
3
|
ConnectedAccountRetrieveResponse as RawConnectedAccountRetrieveResponse,
|
|
4
|
+
type ConnectedAccounts as ClientConnectedAccounts,
|
|
4
5
|
} from '@composio/client/resources/connected-accounts';
|
|
5
6
|
import {
|
|
6
7
|
ConnectedAccountListResponse,
|
|
7
8
|
ConnectedAccountListResponseSchema,
|
|
8
9
|
ConnectedAccountRetrieveResponse,
|
|
9
10
|
ConnectedAccountRetrieveResponseSchema,
|
|
11
|
+
ConnectedAccountRevokeResponse,
|
|
12
|
+
ConnectedAccountRevokeResponseSchema,
|
|
13
|
+
ConnectedAccountCompleteAuthResponse,
|
|
14
|
+
ConnectedAccountCompleteAuthResponseSchema,
|
|
10
15
|
} from '../../types/connectedAccounts.types';
|
|
16
|
+
|
|
17
|
+
// The revoke and complete-auth response types are only reachable through the
|
|
18
|
+
// resource class namespace on the published subpath.
|
|
19
|
+
type RawConnectedAccountRevokeResponse = ClientConnectedAccounts.ConnectedAccountRevokeResponse;
|
|
20
|
+
type RawConnectedAccountCompleteAuthResponse =
|
|
21
|
+
ClientConnectedAccounts.ConnectedAccountCompleteAuthResponse;
|
|
11
22
|
import { ConnectionDataSchema } from '../../types/connectedAccountAuthStates.types';
|
|
12
23
|
import logger from '../logger';
|
|
13
24
|
import { transform } from '../transform';
|
|
14
25
|
|
|
15
26
|
type RawConnectedAccountResponseWithLabels = (
|
|
16
|
-
|
|
|
17
|
-
| RawConnectedAccountListResponse['items'][0]
|
|
27
|
+
RawConnectedAccountRetrieveResponse | RawConnectedAccountListResponse['items'][0]
|
|
18
28
|
) & {
|
|
19
29
|
word_id?: string | null;
|
|
20
30
|
alias?: string | null;
|
|
@@ -117,3 +127,28 @@ export function transformConnectedAccountListResponse(
|
|
|
117
127
|
totalPages: response.total_pages,
|
|
118
128
|
}));
|
|
119
129
|
}
|
|
130
|
+
|
|
131
|
+
export const transformConnectedAccountRevokeResponse = (
|
|
132
|
+
response: RawConnectedAccountRevokeResponse
|
|
133
|
+
): ConnectedAccountRevokeResponse => {
|
|
134
|
+
return transform(response)
|
|
135
|
+
.with(ConnectedAccountRevokeResponseSchema)
|
|
136
|
+
.using(response => ({
|
|
137
|
+
revokedTokens: response.revoked_tokens,
|
|
138
|
+
connectedAccount: {
|
|
139
|
+
id: response.connected_account.id,
|
|
140
|
+
status: response.connected_account.status,
|
|
141
|
+
},
|
|
142
|
+
}));
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
export const transformConnectedAccountCompleteAuthResponse = (
|
|
146
|
+
response: RawConnectedAccountCompleteAuthResponse
|
|
147
|
+
): ConnectedAccountCompleteAuthResponse => {
|
|
148
|
+
return transform(response)
|
|
149
|
+
.with(ConnectedAccountCompleteAuthResponseSchema)
|
|
150
|
+
.using(response => ({
|
|
151
|
+
connectedAccountId: response.connected_account_id,
|
|
152
|
+
toolkitSlug: response.toolkit_slug,
|
|
153
|
+
}));
|
|
154
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CustomDeleteToolkitResponse as RawCustomDeleteToolkitResponse,
|
|
3
|
+
CustomSyncParams as RawCustomSyncParams,
|
|
4
|
+
CustomSyncResponse as RawCustomSyncResponse,
|
|
5
|
+
CustomUpsertParams as RawCustomUpsertParams,
|
|
6
|
+
CustomUpsertResponse as RawCustomUpsertResponse,
|
|
7
|
+
} from '@composio/client/resources/custom';
|
|
8
|
+
import {
|
|
9
|
+
CustomToolkitAuthScheme,
|
|
10
|
+
CustomToolkitDeleteResponse,
|
|
11
|
+
CustomToolkitDeleteResponseSchema,
|
|
12
|
+
CustomToolkitSyncParams,
|
|
13
|
+
CustomToolkitSyncResponse,
|
|
14
|
+
CustomToolkitSyncResponseSchema,
|
|
15
|
+
CustomToolkitUpsertParams,
|
|
16
|
+
CustomToolkitUpsertResponse,
|
|
17
|
+
CustomToolkitUpsertResponseSchema,
|
|
18
|
+
} from '../../types/customToolkits.types';
|
|
19
|
+
import { transform } from '../transform';
|
|
20
|
+
|
|
21
|
+
type RawCustomToolkitAuthScheme = RawCustomUpsertParams['toolkit_config']['auth_schemes'][number];
|
|
22
|
+
|
|
23
|
+
const transformCustomToolkitAuthScheme = (
|
|
24
|
+
scheme: CustomToolkitAuthScheme
|
|
25
|
+
): RawCustomToolkitAuthScheme => {
|
|
26
|
+
switch (scheme.mode) {
|
|
27
|
+
case 'NO_AUTH':
|
|
28
|
+
return { mode: 'NO_AUTH' };
|
|
29
|
+
case 'API_KEY':
|
|
30
|
+
return {
|
|
31
|
+
mode: 'API_KEY',
|
|
32
|
+
headers: scheme.headers,
|
|
33
|
+
api_key_field: scheme.apiKeyField && {
|
|
34
|
+
display_name: scheme.apiKeyField.displayName,
|
|
35
|
+
description: scheme.apiKeyField.description,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
case 'DCR_OAUTH':
|
|
39
|
+
return { mode: 'DCR_OAUTH', discovery_url: scheme.discoveryUrl };
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const transformCustomToolkitUpsertParams = (
|
|
44
|
+
params: CustomToolkitUpsertParams
|
|
45
|
+
): RawCustomUpsertParams => ({
|
|
46
|
+
slug: params.slug,
|
|
47
|
+
toolkit_config: {
|
|
48
|
+
name: params.toolkitConfig.name,
|
|
49
|
+
app_url: params.toolkitConfig.appUrl,
|
|
50
|
+
logo_file: params.toolkitConfig.logoFile && {
|
|
51
|
+
content: params.toolkitConfig.logoFile.content,
|
|
52
|
+
mime_type: params.toolkitConfig.logoFile.mimeType,
|
|
53
|
+
},
|
|
54
|
+
auth_schemes: params.toolkitConfig.authSchemes.map(transformCustomToolkitAuthScheme),
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
export const transformCustomToolkitUpsertResponse = (
|
|
59
|
+
response: RawCustomUpsertResponse
|
|
60
|
+
): CustomToolkitUpsertResponse => {
|
|
61
|
+
return transform(response)
|
|
62
|
+
.with(CustomToolkitUpsertResponseSchema)
|
|
63
|
+
.using(response => ({ slug: response.slug }));
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const transformCustomToolkitSyncParams = (
|
|
67
|
+
slug: string,
|
|
68
|
+
params: CustomToolkitSyncParams
|
|
69
|
+
): RawCustomSyncParams => ({
|
|
70
|
+
slug,
|
|
71
|
+
connected_account_id: params.connectedAccountId,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
export const transformCustomToolkitSyncResponse = (
|
|
75
|
+
response: RawCustomSyncResponse
|
|
76
|
+
): CustomToolkitSyncResponse => {
|
|
77
|
+
return transform(response)
|
|
78
|
+
.with(CustomToolkitSyncResponseSchema)
|
|
79
|
+
.using(response => ({
|
|
80
|
+
slug: response.slug,
|
|
81
|
+
version: response.version,
|
|
82
|
+
syncedCount: response.synced_count,
|
|
83
|
+
}));
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const transformCustomToolkitDeleteResponse = (
|
|
87
|
+
response: RawCustomDeleteToolkitResponse
|
|
88
|
+
): CustomToolkitDeleteResponse => {
|
|
89
|
+
return transform(response)
|
|
90
|
+
.with(CustomToolkitDeleteResponseSchema)
|
|
91
|
+
.using(response => ({
|
|
92
|
+
slug: response.slug,
|
|
93
|
+
deleted: response.deleted,
|
|
94
|
+
revokeJobIds: response.revoke_job_ids,
|
|
95
|
+
authConfigsDeleted: response.auth_configs_deleted,
|
|
96
|
+
connectedAccountsDeleted: response.connected_accounts_deleted,
|
|
97
|
+
}));
|
|
98
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { KeyringListTransferKeysResponse as RawKeyringListTransferKeysResponse } from '@composio/client/resources/keyring';
|
|
2
|
+
import {
|
|
3
|
+
KeyringTransferKeysResponse,
|
|
4
|
+
KeyringTransferKeysResponseSchema,
|
|
5
|
+
} from '../../types/keyring.types';
|
|
6
|
+
import { transform } from '../transform';
|
|
7
|
+
|
|
8
|
+
export const transformKeyringTransferKeysResponse = (
|
|
9
|
+
response: RawKeyringListTransferKeysResponse
|
|
10
|
+
): KeyringTransferKeysResponse => {
|
|
11
|
+
return transform(response)
|
|
12
|
+
.with(KeyringTransferKeysResponseSchema)
|
|
13
|
+
.using(response => ({
|
|
14
|
+
activeKid: response.active_kid,
|
|
15
|
+
keys: response.keys.map(key => ({
|
|
16
|
+
kty: key.kty,
|
|
17
|
+
n: key.n,
|
|
18
|
+
e: key.e,
|
|
19
|
+
alg: key.alg,
|
|
20
|
+
use: key.use,
|
|
21
|
+
kid: key.kid,
|
|
22
|
+
})),
|
|
23
|
+
}));
|
|
24
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
LogCreateToolExecutionParams as RawLogSearchParams,
|
|
3
|
+
LogCreateToolExecutionResponse as RawLogSearchResponse,
|
|
4
|
+
LogRetrieveToolExecutionResponse as RawToolExecutionLogDetail,
|
|
5
|
+
} from '@composio/client/resources/logs';
|
|
6
|
+
import {
|
|
7
|
+
LogSearchParams,
|
|
8
|
+
LogSearchResponse,
|
|
9
|
+
LogSearchResponseSchema,
|
|
10
|
+
ToolExecutionLog,
|
|
11
|
+
ToolExecutionLogDetail,
|
|
12
|
+
ToolExecutionLogDetailSchema,
|
|
13
|
+
ToolExecutionLogSchema,
|
|
14
|
+
} from '../../types/logs.types';
|
|
15
|
+
import { transform } from '../transform';
|
|
16
|
+
|
|
17
|
+
export const transformLogSearchParams = (params: LogSearchParams): RawLogSearchParams => ({
|
|
18
|
+
limit: params.limit,
|
|
19
|
+
cursor: params.cursor,
|
|
20
|
+
filters: params.filters,
|
|
21
|
+
time_range: params.timeRange,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export const transformToolExecutionLog = (
|
|
25
|
+
response: RawLogSearchResponse['logs'][number]
|
|
26
|
+
): ToolExecutionLog => {
|
|
27
|
+
return transform(response)
|
|
28
|
+
.with(ToolExecutionLogSchema)
|
|
29
|
+
.using(response => ({
|
|
30
|
+
id: response.id,
|
|
31
|
+
timestamp: response.timestamp,
|
|
32
|
+
type: response.type,
|
|
33
|
+
status: response.status,
|
|
34
|
+
level: response.level,
|
|
35
|
+
message: response.message,
|
|
36
|
+
metadata: response.metadata,
|
|
37
|
+
metrics: response.metrics,
|
|
38
|
+
parent: response.parent
|
|
39
|
+
? { logId: response.parent.log_id, toolSlug: response.parent.tool_slug }
|
|
40
|
+
: null,
|
|
41
|
+
}));
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const transformLogSearchResponse = (response: RawLogSearchResponse): LogSearchResponse => {
|
|
45
|
+
return transform(response)
|
|
46
|
+
.with(LogSearchResponseSchema)
|
|
47
|
+
.using(response => ({
|
|
48
|
+
logs: response.logs.map(transformToolExecutionLog),
|
|
49
|
+
nextCursor: response.next_cursor,
|
|
50
|
+
}));
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const transformToolExecutionLogDetail = (
|
|
54
|
+
response: RawToolExecutionLogDetail
|
|
55
|
+
): ToolExecutionLogDetail => {
|
|
56
|
+
return transform(response)
|
|
57
|
+
.with(ToolExecutionLogDetailSchema)
|
|
58
|
+
.using(response => ({
|
|
59
|
+
id: response.id,
|
|
60
|
+
timestamp: response.timestamp,
|
|
61
|
+
type: response.type,
|
|
62
|
+
status: response.status,
|
|
63
|
+
level: response.level,
|
|
64
|
+
message: response.message,
|
|
65
|
+
metadata: response.metadata,
|
|
66
|
+
metrics: response.metrics,
|
|
67
|
+
parent: response.parent
|
|
68
|
+
? { logId: response.parent.log_id, toolSlug: response.parent.tool_slug }
|
|
69
|
+
: null,
|
|
70
|
+
timings: response.timings
|
|
71
|
+
? { startTime: response.timings.start_time, endTime: response.timings.end_time }
|
|
72
|
+
: undefined,
|
|
73
|
+
context: {
|
|
74
|
+
sessionId: response.context.session_id,
|
|
75
|
+
traceId: response.context.trace_id,
|
|
76
|
+
requestId: response.context.request_id,
|
|
77
|
+
},
|
|
78
|
+
source: {
|
|
79
|
+
host: response.source.host,
|
|
80
|
+
framework: response.source.framework,
|
|
81
|
+
language: response.source.language,
|
|
82
|
+
},
|
|
83
|
+
data: response.data,
|
|
84
|
+
}));
|
|
85
|
+
};
|