@devries-cameron20 / composio Mirror · read-only / commits / 1239853a9
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.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 07:15 UTC

fix(cli): enforce the consumer permission gate on `composio proxy` (#5093)

## Summary `composio proxy` sends side-effecting toolkit calls through a consumer Tool Router session, but it never ran the permission gate that `composio execute` runs. On an enhanced-controls project, the org's `ask_every_call` / `ask_once` / `always_deny` policy did not apply to proxied calls. Refs [PRDE-1702](https://linear.app/composio/issue/PRDE-1702/investigate-cli-get-session-api-credential-exposure). ## What changed - `composio proxy` runs `gateToolExecution` after the session resolves and before `proxy_execute` is sent. - The gate is keyed on the connected account the session uses, read from the resolved session (`connectedAccounts[toolkit]`) the same way the execute path does. That is the `--account` pin when given, otherwise the default account the session selects. - Denials and approval prompts are the same as `composio execute`: `ToolPermissionDeniedError` for `always_deny` (or when prompts are disabled), the localhost approval page for `ask_*`. Policy keys that apply to a proxied call: the project default, `*:<account>`, and `<toolkit>:<account>`. Per-tool overrides (`GMAIL_SEND_EMAIL:<account>`) name catalog tools, and a raw HTTP call through the proxy is not one, so they don't apply here. Use an account-wide override or the default to restrict proxy access. ## Test `proxy.cmd.test.ts`: default `allow_all`, override `*:con_gmail_work → always_deny`, no `--account`. The session pins `con_gmail_work` by default, the command fails with `ToolPermissionDeniedError`, and `proxy_execute` is never called. The test fails if the gate is keyed on the `--account` selection instead of the session's account. ## Checks - `pnpm typecheck` (repo root) - `pnpm --filter @composio/cli run lint:effect`: 0 diagnostics - `pnpm --filter @composio/cli test`: 209 files, 2374 tests passing

Alberto Schiabel committed Oct 23, 2026 at 22:33 UTC 1239853a9356c5c9035c791fba601eb32f6a9ca0
3 files changed +126 -10
ts/packages/cli/CHANGELOG.md
+6
@@ -12,6 +12,12 @@
12
13 ### Patch Changes
14
15 +- `composio proxy` now enforces the consumer permission policy that
16 + `composio execute` enforces, checked against the connected account the
17 + request uses. A denied request fails with the same permission error, and a
18 + request that needs approval opens the same approval page, before anything is
19 + sent.
20 +
21 - A tool call or proxied request that a session hook blocks is now reported as
22 a failure carrying the hook's message. `composio execute` prints it as a
23 failed call (`successful: false`) with the message in `error`; on consumer
ts/packages/cli/src/commands/proxy.cmd.ts
+21 -10
@@ -9,6 +9,7 @@ import { ExpectedFailure } from 'src/effects/expected-failure';
9 import { requestError } from 'src/effects/request-error';
10 import { resolveOptionalTextInput } from 'src/effects/resolve-optional-text-input';
11 import { resolveToolRouterSession } from 'src/effects/create-tool-router-session';
12 +import { gateToolExecution } from 'src/services/tool-permissions';
13 import {
14 getFreshConsumerConnectedToolkitsFromCache,
15 refreshConsumerConnectedToolkitsCache,
@@ -351,16 +352,26 @@ export const proxyCmd = Command.make('proxy', {
352 selector: account,
353 })
354 : undefined;
354 - const { sessionId } = yield* resolveToolRouterSession(client, consumerUserId, {
355 - toolkits: [normalizedToolkit],
356 - connectedAccounts: selectedConnectedAccountId
357 - ? { [normalizedToolkit]: selectedConnectedAccountId }
358 - : undefined,
359 - cacheScope: {
360 - orgId: resolvedProject.orgId,
361 - projectId: resolvedProject.projectId,
362 - consumerUserId,
363 - },
355 + const { sessionId, permissionSnapshot, connectedAccounts, connectedAccountWordIds } =
356 + yield* resolveToolRouterSession(client, consumerUserId, {
357 + toolkits: [normalizedToolkit],
358 + connectedAccounts: selectedConnectedAccountId
359 + ? { [normalizedToolkit]: selectedConnectedAccountId }
360 + : undefined,
361 + cacheScope: {
362 + orgId: resolvedProject.orgId,
363 + projectId: resolvedProject.projectId,
364 + consumerUserId,
365 + },
366 + });
367 +
368 + // Same consumer permission gate as `composio execute`, checked against
369 + // the account the session will use (explicit `--account` or default).
370 + yield* gateToolExecution({
371 + toolSlug: normalizedToolkit,
372 + connectedAccountId: connectedAccounts?.[normalizedToolkit],
373 + connectedAccountWordId: connectedAccountWordIds?.[normalizedToolkit],
374 + snapshot: permissionSnapshot,
375 });
376
377 const failed = (cause: unknown) =>
ts/packages/cli/test/src/commands/proxy.cmd.test.ts
+99
@@ -13,6 +13,7 @@ import {
13 ReportedProxyCommandError,
14 } from 'src/commands/proxy.cmd';
15 import * as consumerShortTermCache from 'src/services/consumer-short-term-cache';
16 +import * as toolPermissions from 'src/services/tool-permissions';
17 import { cli, MockConsole, TestLive } from 'test/__utils__';
18
19 const testConfigProvider = ConfigProvider.fromEnv({
@@ -397,4 +398,102 @@ describe('CLI: composio proxy', () => {
398 );
399 }
400 );
401 +
402 + layer(TestLive({ baseConfigProvider: testConfigProvider, fixture: 'global-test-user-id' }))(
403 + '[Given] an always_deny override on the default account [Then] proxy is denied before proxy_execute',
404 + it => {
405 + it.effect('gates on the account the session resolves when --account is omitted', () =>
406 + Effect.gen(function* () {
407 + vi.spyOn(toolPermissions, 'getConsumerPermissionSnapshot').mockImplementation(params =>
408 + Effect.succeed({
409 + orgId: params.orgId,
410 + projectId: params.projectId,
411 + consumerUserId: params.consumerUserId,
412 + enhancedControlsEnabled: true,
413 + permissions: {
414 + default: 'allow_all',
415 + overrides: { '*:con_gmail_work': 'always_deny' },
416 + },
417 + connectedAccountIds: [],
418 + fetchedAt: 1_767_225_600_000,
419 + })
420 + );
421 +
422 + let createParams: SessionCreateParams | undefined;
423 + let proxyCalled = false;
424 + const live = TestLive({
425 + baseConfigProvider: testConfigProvider,
426 + fixture: 'global-test-user-id',
427 + cliUserConfig: { experimentalFeatures: { multi_account: false } },
428 + connectedAccountsData: {
429 + items: [
430 + {
431 + id: 'con_gmail_work',
432 + alias: 'work',
433 + word_id: 'gmail-work',
434 + status: 'ACTIVE',
435 + status_reason: null,
436 + is_disabled: false,
437 + user_id: 'consumer-user-org_test',
438 + toolkit: { slug: 'gmail' },
439 + auth_config: {
440 + id: 'ac_gmail_oauth',
441 + auth_scheme: 'OAUTH2',
442 + is_composio_managed: true,
443 + is_disabled: false,
444 + },
445 + created_at: '2026-01-01T00:00:00.000Z',
446 + updated_at: '2026-01-01T00:00:00.000Z',
447 + test_request_endpoint: '',
448 + },
449 + ],
450 + },
451 + toolRouter: {
452 + create: (params: SessionCreateParams) =>
453 + Effect.sync(() => {
454 + createParams = params;
455 + return {
456 + session_id: 'trs_proxy_test',
457 + config: {
458 + user_id: params.user_id,
459 + execute: {},
460 + search: {},
461 + preload: { tools: [] },
462 + instant: false,
463 + },
464 + config_version: 1,
465 + mcp: { type: 'http' as const, url: 'https://mcp.test.composio.dev' },
466 + tool_router_tools: [],
467 + };
468 + }),
469 + proxyExecute: () =>
470 + Effect.sync(() => {
471 + proxyCalled = true;
472 + return {
473 + result_type: 'completed' as const,
474 + status: 200,
475 + data: { ok: true },
476 + headers: { 'content-type': 'application/json' },
477 + };
478 + }),
479 + },
480 + });
481 +
482 + const failure = yield* cli([
483 + 'proxy',
484 + 'https://gmail.googleapis.com/gmail/v1/users/me/drafts',
485 + '--toolkit',
486 + 'gmail',
487 + '-X',
488 + 'post',
489 + ]).pipe(Effect.flip, Effect.provide(live));
490 +
491 + expect(createParams?.connected_accounts).toEqual({ gmail: 'con_gmail_work' });
492 + expect(failure).toBeInstanceOf(toolPermissions.ToolPermissionDeniedError);
493 + expect(failure).toMatchObject({ deniedBy: 'permissions', toolSlug: 'gmail' });
494 + expect(proxyCalled).toBe(false);
495 + })
496 + );
497 + }
498 + );
499 });