Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
fix(connected-accounts): validate ACL input in ToolRouterSession.authorize()
venkat8214a5b52b60e1
diff --git a/ts/packages/core/src/models/ToolRouterSession.ts b/ts/packages/core/src/models/ToolRouterSession.tsindex bf6e5eb6f..c50982977 100644--- a/ts/packages/core/src/models/ToolRouterSession.ts+++ b/ts/packages/core/src/models/ToolRouterSession.ts@@ -27,10 +27,13 @@ import { SessionMetaToolOptions } from '../types/modifiers.types';import { ConnectionRequest } from '../types/connectionRequest.types';import { createConnectionRequest } from './ConnectionRequest';import {+ ConnectedAccountAclConfigSchema,ConnectedAccountStatuses,ConnectedAccountType,+ ConnectedAccountTypeSchema,ConnectedAccountAclConfig,} from '../types/connectedAccounts.types';+import { z } from 'zod/v3';import { transform } from '../utils/transform';import { ToolkitConnectionStateSchema } from '../types/toolRouter.types';import { ComposioAclOnlyForSharedError, ValidationError } from '../errors';@@ -69,6 +72,21 @@ const COMPOSIO_MULTI_EXECUTE_TOOL = 'COMPOSIO_MULTI_EXECUTE_TOOL';export const DIRECT_CUSTOM_TOOL_DESCRIPTION_PREFIX ='[Direct tool - call directly, no search needed beforehand.]';+/**+ * Options accepted by {@link ToolRouterSession.authorize}.+ *+ * Validated at the SDK boundary so callers get clear `ValidationError`s for+ * oversized ACL lists or invalid user IDs — same Zod caps as the equivalent+ * `composio.connectedAccounts.link()` path (≤1000 entries per list, each+ * user_id 1..256 chars). Caught Bugbot review.+ */+const AuthorizeOptionsSchema = z.object({+ callbackUrl: z.string().optional(),+ alias: z.string().optional(),+ accountType: ConnectedAccountTypeSchema.optional(),+ aclConfigForShared: ConnectedAccountAclConfigSchema.optional(),+});+export class ToolRouterSession<TToolCollection,TTool,@@ -312,6 +330,12 @@ export class ToolRouterSession<* `accountType` and `aclConfigForShared` (Hermes #9860, #9902) let the* caller create a SHARED connection with a per-user ACL in one flow.* Default behaviour (omit both) creates a PRIVATE connection.+ *+ * `aclConfigForShared` is validated through `ConnectedAccountAclConfigSchema`+ * — same Zod caps as `composio.connectedAccounts.link()` (≤1000 entries+ * per list, each user_id 1..256 chars). Invalid input throws+ * `ValidationError` at the SDK boundary instead of hitting an opaque+ * backend 400.*/async authorize(toolkit: string,@@ -322,25 +346,32 @@ export class ToolRouterSession<aclConfigForShared?: ConnectedAccountAclConfig;}): Promise<ConnectionRequest> {+ const requestOptions = AuthorizeOptionsSchema.safeParse(options ?? {});+ if (!requestOptions.success) {+ throw new ValidationError('Failed to parse tool router authorize options', {+ cause: requestOptions.error,+ });+ }+ const opts = requestOptions.data;const aclWire: SessionLinkParams.ACLConfigForShared | undefined =- options?.aclConfigForShared === undefined+ opts.aclConfigForShared === undefined? undefined: {- ...(options.aclConfigForShared.allowAllUsers !== undefined && {- allow_all_users: options.aclConfigForShared.allowAllUsers,+ ...(opts.aclConfigForShared.allowAllUsers !== undefined && {+ allow_all_users: opts.aclConfigForShared.allowAllUsers,}),- ...(options.aclConfigForShared.allowedUserIds !== undefined && {- allowed_user_ids: options.aclConfigForShared.allowedUserIds,+ ...(opts.aclConfigForShared.allowedUserIds !== undefined && {+ allowed_user_ids: opts.aclConfigForShared.allowedUserIds,}),- ...(options.aclConfigForShared.notAllowedUserIds !== undefined && {- not_allowed_user_ids: options.aclConfigForShared.notAllowedUserIds,+ ...(opts.aclConfigForShared.notAllowedUserIds !== undefined && {+ not_allowed_user_ids: opts.aclConfigForShared.notAllowedUserIds,}),};const body: SessionLinkParams = {toolkit,- ...(options?.callbackUrl !== undefined && { callback_url: options.callbackUrl }),- ...(options?.alias !== undefined && { alias: options.alias }),- ...(options?.accountType !== undefined && { account_type: options.accountType }),+ ...(opts.callbackUrl !== undefined && { callback_url: opts.callbackUrl }),+ ...(opts.alias !== undefined && { alias: opts.alias }),+ ...(opts.accountType !== undefined && { account_type: opts.accountType }),...(aclWire !== undefined && { acl_config_for_shared: aclWire }),};diff --git a/ts/packages/core/test/models/toolRouter.test.ts b/ts/packages/core/test/models/toolRouter.test.tsindex 886bd28fc..66b311d06 100644--- a/ts/packages/core/test/models/toolRouter.test.ts+++ b/ts/packages/core/test/models/toolRouter.test.ts@@ -1848,6 +1848,72 @@ describe('ToolRouter', () => {expect(connectionRequest).toHaveProperty('toString');expect(typeof connectionRequest.waitForConnection).toBe('function');});++ // Bugbot-flagged gap: authorize() was passing aclConfigForShared straight+ // to the wire while link() validated through Zod. These tests pin the+ // parity — same 1000-entry list cap, same 256-char user_id cap.+ it('forwards accountType + nested acl_config_for_shared on the wire', async () => {+ mockClient.toolRouter.session.link.mockResolvedValueOnce(mockLinkResponse);++ const session = await toolRouter.create(userId);+ await session.authorize(toolkit, {+ accountType: 'SHARED',+ aclConfigForShared: {+ allowAllUsers: true,+ notAllowedUserIds: ['user_bob'],+ },+ });++ expect(mockClient.toolRouter.session.link).toHaveBeenCalledWith(sessionId, {+ toolkit,+ account_type: 'SHARED',+ acl_config_for_shared: {+ allow_all_users: true,+ not_allowed_user_ids: ['user_bob'],+ },+ });+ });++ it('throws ValidationError when allowedUserIds exceeds the 1000-entry cap', async () => {+ const session = await toolRouter.create(userId);+ const oversizedList = Array.from({ length: 1001 }, (_, i) => `user_${i}`);++ await expect(+ session.authorize(toolkit, {+ accountType: 'SHARED',+ aclConfigForShared: { allowedUserIds: oversizedList },+ })+ ).rejects.toMatchObject({ name: 'ValidationError' });++ expect(mockClient.toolRouter.session.link).not.toHaveBeenCalled();+ });++ it('throws ValidationError when a user_id exceeds the 256-char length cap', async () => {+ const session = await toolRouter.create(userId);+ const tooLongUserId = 'u'.repeat(257);++ await expect(+ session.authorize(toolkit, {+ accountType: 'SHARED',+ aclConfigForShared: { allowedUserIds: [tooLongUserId] },+ })+ ).rejects.toMatchObject({ name: 'ValidationError' });++ expect(mockClient.toolRouter.session.link).not.toHaveBeenCalled();+ });++ it('throws ValidationError when a user_id is empty', async () => {+ const session = await toolRouter.create(userId);++ await expect(+ session.authorize(toolkit, {+ accountType: 'SHARED',+ aclConfigForShared: { notAllowedUserIds: [''] },+ })+ ).rejects.toMatchObject({ name: 'ValidationError' });++ expect(mockClient.toolRouter.session.link).not.toHaveBeenCalled();+ });});describe('toolkits function', () => {