@devries-cameron20 / composio-1 / commits / 00ddb3012
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

fix(cli): curate piped JSON output for toolkits info, validate redirect URL scheme

- Add formatToolkitInfoJson() to produce a stable, curated JSON schema for piped output instead of leaking the raw SessionToolkitItem response - Validate redirect URL scheme (http/https only) before calling open() to prevent opening arbitrary URLs from a compromised API response

jkomyno committed Feb 26, 2026 at 01:45 UTC 00ddb3012f3bb3bcf42a5d6b1e7eac0ce8b3727f
3 files changed +52 -11
ts/packages/cli/src/commands/connected-accounts/commands/connected-accounts.link.cmd.ts
+23 -9
@@ -43,15 +43,29 @@ const waitForActiveConnection = (
43 yield* ui.output(redirectUrl);
44
45 if (!noBrowser) {
46 - yield* Effect.tryPromise(() => open(redirectUrl, { wait: false })).pipe(
47 - Effect.catchAll(error =>
48 - Effect.gen(function* () {
49 - yield* Effect.logDebug('Failed to open browser:', error);
50 - yield* ui.log.warn('Could not open the browser automatically.');
51 - yield* ui.log.info('Tip: try using `--no-browser` and open the URL manually.');
52 - })
53 - )
54 - );
46 + // Validate URL scheme before opening — prevent non-HTTPS redirects
47 + let urlSchemeValid = false;
48 + try {
49 + const parsed = new URL(redirectUrl);
50 + urlSchemeValid = parsed.protocol === 'https:' || parsed.protocol === 'http:';
51 + } catch {
52 + // Malformed URL — fall through to the warning below
53 + }
54 +
55 + if (!urlSchemeValid) {
56 + yield* ui.log.warn(`Redirect URL has an unexpected scheme: ${redirectUrl}`);
57 + yield* ui.log.info('Open the URL manually if you trust the source.');
58 + } else {
59 + yield* Effect.tryPromise(() => open(redirectUrl, { wait: false })).pipe(
60 + Effect.catchAll(error =>
61 + Effect.gen(function* () {
62 + yield* Effect.logDebug('Failed to open browser:', error);
63 + yield* ui.log.warn('Could not open the browser automatically.');
64 + yield* ui.log.info('Tip: try using `--no-browser` and open the URL manually.');
65 + })
66 + )
67 + );
68 + }
69 }
70
71 // Poll until the connected account becomes ACTIVE
ts/packages/cli/src/commands/toolkits/commands/toolkits.info.cmd.ts
+2 -2
@@ -4,7 +4,7 @@ import { ComposioClientSingleton, ComposioToolkitsRepository } from 'src/service
4 import { TerminalUI } from 'src/services/terminal-ui';
5 import { requireAuth } from 'src/effects/require-auth';
6 import { createToolRouterSession } from 'src/effects/create-tool-router-session';
7 -import { formatToolkitInfo } from '../format';
7 +import { formatToolkitInfo, formatToolkitInfoJson } from '../format';
8
9 const slug = Args.text({ name: 'slug' }).pipe(
10 Args.withDescription('Toolkit slug (e.g. "gmail")'),
@@ -108,6 +108,6 @@ export const toolkitsCmd$Info = Command.make('info', { slug, userId }, ({ slug,
108 `To list tools in this toolkit:\n> composio tools list --toolkits "${toolkit.slug}"`
109 );
110
111 - yield* ui.output(JSON.stringify(toolkit, null, 2));
111 + yield* ui.output(formatToolkitInfoJson(toolkit));
112 })
113 ).pipe(Command.withDescription('View details of a specific toolkit.'));
ts/packages/cli/src/commands/toolkits/format.ts
+27
@@ -105,6 +105,33 @@ export function formatToolkitInfo(toolkit: SessionToolkitItem): string {
105 return lines.join('\n');
106 }
107
108 +/**
109 + * Format a single session toolkit as JSON for piped output.
110 + * Produces a stable, curated schema — does not leak the raw API response.
111 + */
112 +export function formatToolkitInfoJson(toolkit: SessionToolkitItem): string {
113 + return JSON.stringify(
114 + {
115 + name: toolkit.name,
116 + slug: toolkit.slug,
117 + description: toolkit.meta.description,
118 + is_no_auth: toolkit.is_no_auth,
119 + enabled: toolkit.enabled,
120 + connected: toolkit.connected_account
121 + ? {
122 + status: toolkit.connected_account.status,
123 + id: toolkit.connected_account.id,
124 + auth_scheme: toolkit.connected_account.auth_config?.auth_scheme ?? null,
125 + is_composio_managed: toolkit.connected_account.auth_config?.is_composio_managed ?? null,
126 + }
127 + : null,
128 + composio_managed_auth_schemes: toolkit.composio_managed_auth_schemes,
129 + },
130 + null,
131 + 2
132 + );
133 +}
134 +
135 // ---------- Legacy format functions (used by non-migrated commands) ----------
136
137 /**