Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
cd8509f
fix(core): make permissions.allow restrict the tool schemas sent to t…
yiliang114 Aug 23, 2026
6af0884
Merge branch 'main' into fix/issue-9827-permissions-tool-schemas
wenshao Aug 23, 2026
a554edb
fix(core): honor permissions.allow in the list_directory opt-in gate …
yiliang114 Aug 24, 2026
b8ba258
fix(core): keep plan-mode lifecycle tools registered under the allowl…
yiliang114 Aug 24, 2026
477c36f
docs(sdk): correct allowedTools registry-allowlist contract (#9827)
yiliang114 Aug 24, 2026
105e5f0
docs(settings): note plan-mode lifecycle exemption in the allowlist (…
yiliang114 Aug 24, 2026
4d30e18
fix(core): exempt the computer_use__* family from the registry allowl…
yiliang114 Aug 24, 2026
c68f473
fix(core): gate command-discovered tools through the registry allowli…
yiliang114 Aug 24, 2026
4f1ee39
fix(core): make registry-allowlist membership monotonic within the se…
yiliang114 Aug 24, 2026
a9031c1
fix(core): narrow the skill allowedTools grant contract to restart-sc…
yiliang114 Aug 24, 2026
e9afe40
fix(core): count ask rules toward registry-allowlist membership (#9827)
yiliang114 Aug 24, 2026
1494aad
docs(settings): note that ask rules keep tools registered under allow…
yiliang114 Aug 24, 2026
de9a8e3
test(cli): pin registry-allowlist strip in bare mode (#9827)
yiliang114 Aug 24, 2026
c965468
fix(core): attribute registry-allowlist misses to permissions.allow (…
yiliang114 Aug 24, 2026
df5fada
test(core): pin resolveToolName coverage of every ToolNames entry (#9…
yiliang114 Aug 24, 2026
b0adfa7
fix(core): expose isPermissionsAllowListActive on scoped PM shims (#9…
yiliang114 Aug 24, 2026
23189f2
fix(core): honour ask-only list_directory coverage in the opt-in gate…
yiliang114 Aug 24, 2026
55f1fb5
docs: align registry-allowlist contract wording across docs and JSDoc…
yiliang114 Aug 24, 2026
0869a84
docs: scope settings.md removal and whole-tool-deny claims precisely …
yiliang114 Aug 24, 2026
f25d7ce
Merge remote-tracking branch 'origin/main' into fix/issue-9827-permis…
yiliang114 Aug 24, 2026
be96336
fix(core): count merged allow coverage in the list_directory opt-in g…
yiliang114 Aug 24, 2026
519be05
test(core): pin activation source and merged-allow coverage of the li…
yiliang114 Aug 24, 2026
56b1db6
fix(core): attribute scheduler denials to permissions.allow only for …
yiliang114 Aug 24, 2026
ced9a08
test(core): pin the covered-tool fallback for scheduler denial messag…
yiliang114 Aug 24, 2026
5437a89
fix(core): register request_shutdown in the permission rule alias map…
yiliang114 Aug 24, 2026
a4ee647
fix(core): guard the list_directory allowlist gate against non-string…
yiliang114 Aug 24, 2026
640ec59
fix(core): exempt task_stop from the permissions.allow registry gate …
yiliang114 Aug 24, 2026
63970a3
fix(core): keep shim denials on the pre-#9827 message when coverage i…
yiliang114 Aug 24, 2026
6c2694b
test(core): pin that ask-only rules never activate the allowlist (#9827)
yiliang114 Aug 24, 2026
c9b670e
fix(core): exempt tool_search from the permissions.allow registry gat…
yiliang114 Aug 25, 2026
3ca966c
test(core): pin the deny-rule arm's precedence in the scheduler permi…
yiliang114 Aug 25, 2026
7283ed1
test(core): pin deny/ask sibling semantics at the discovery gate (#9827)
yiliang114 Aug 25, 2026
5e63280
docs: match the allowlist activation wording to the real predicate (#…
yiliang114 Aug 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/users/configuration/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,11 +418,11 @@ The permissions system provides fine-grained control over which tools can run, w

The first matching rule wins. Rules use the format `"ToolName"` or `"ToolName(specifier)"`.

| Setting | Type | Description | Default |
| ------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------- | ----------- |
| `permissions.allow` | array of strings | Rules for auto-approved tool calls (no confirmation needed). Merged across all scopes (user + project + system). | `undefined` |
| `permissions.ask` | array of strings | Rules for tool calls that always require user confirmation. Takes priority over `allow`. | `undefined` |
| `permissions.deny` | array of strings | Rules for blocked tool calls. Highest priority — overrides both `allow` and `ask`. | `undefined` |
| Setting | Type | Description | Default |
| ------------------- | ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| `permissions.allow` | array of strings | Rules for auto-approved tool calls (no confirmation needed). Merged across all scopes (user + project + system). Also acts as a registry-level allowlist: when at least one allow rule is configured, built-in tools not covered by any allow rule are not registered at all — they disappear from `/tools` and their schemas are never sent to the model (MCP tools and the `--json-schema` `structured_output` contract are exempt). Requires restart. | `undefined` |
| `permissions.ask` | array of strings | Rules for tool calls that always require user confirmation. Takes priority over `allow`. | `undefined` |
| `permissions.deny` | array of strings | Rules for blocked tool calls. Highest priority — overrides both `allow` and `ask`. A whole-tool deny rule (no specifier) also removes the tool from the registry. | `undefined` |

**Tool name aliases (any of these work in rules):**

Expand Down
69 changes: 69 additions & 0 deletions packages/cli/src/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4017,6 +4017,75 @@ describe('loadCliConfig safe mode', () => {
});
});

describe('loadCliConfig registry allowlist wiring (#9827)', () => {
const originalArgv = process.argv;

beforeEach(() => {
vi.resetAllMocks();
vi.mocked(os.homedir).mockReturnValue('/mock/home/user');
vi.stubEnv('GEMINI_API_KEY', 'test-api-key');
vi.spyOn(process, 'cwd').mockReturnValue(
path.resolve(path.sep, 'home', 'user', 'project'),
);
});

afterEach(() => {
process.argv = originalArgv;
vi.unstubAllEnvs();
vi.restoreAllMocks();
});

it('passes settings.permissions.allow as the registry allowlist', async () => {
process.argv = ['node', 'script.js'];
const argv = await parseArguments();
const settings: Settings = {
permissions: {
allow: ['ReadFile', 'Shell'],
},
};
const config = await loadCliConfig(settings, argv, undefined, []);

expect(config.getRegistryAllowList()).toEqual(['ReadFile', 'Shell']);
});

it('does not treat --allowed-tools as a registry allowlist', async () => {
process.argv = ['node', 'script.js', '--allowed-tools', 'ReadFile'];
const argv = await parseArguments();
const config = await loadCliConfig({}, argv, undefined, []);

// Auto-approval grant only — the full toolset stays registered
expect(config.getPermissionsAllow()).toContain('ReadFile');
expect(config.getRegistryAllowList()).toEqual([]);
});

it('does not treat the legacy tools.allowed key as a registry allowlist', async () => {
process.argv = ['node', 'script.js'];
const argv = await parseArguments();
const settings: Settings = {
tools: {
allowed: ['ShellTool'],
},
};
const config = await loadCliConfig(settings, argv, undefined, []);

expect(config.getPermissionsAllow()).toContain('ShellTool');
expect(config.getRegistryAllowList()).toEqual([]);
});

it('strips the registry allowlist in safe mode', async () => {
process.argv = ['node', 'script.js', '--safe-mode'];
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
const argv = await parseArguments();
const settings: Settings = {
permissions: {
allow: ['ReadFile'],
},
};
const config = await loadCliConfig(settings, argv, undefined, []);

expect(config.getRegistryAllowList()).toEqual([]);
});
});

describe('loadCliConfig chatCompression', () => {
const originalArgv = process.argv;

Expand Down
10 changes: 10 additions & 0 deletions packages/cli/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2209,6 +2209,16 @@ export async function loadCliConfig(
allow: mergedAllow.length > 0 ? mergedAllow : undefined,
ask: mergedAsk.length > 0 ? mergedAsk : undefined,
deny: mergedDeny.length > 0 ? mergedDeny : undefined,
// Only `settings.permissions.allow` (never `--allowed-tools` nor the
// legacy `tools.allowed` key, which stay pure auto-approval grants)
// activates the registry-level allowlist that hides unlisted built-in
// tools from the model request (#9827).
registryAllowList:
bareMode || safeMode
? undefined
: settings.permissions?.allow?.length
? settings.permissions.allow
: undefined,
Comment on lines +2205 to +2210

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed real at HEAD — the full chain reproduces (persist Bash(npm test) via "Always allow" -> next start registryAllowList=["Bash(npm test)"], allowlist active, read_file/edit/grep_search/glob/... all isToolEnabled=false). This directly violates the mid-session invariant the PR documents for itself, one restart later and silently.

I'm escalating rather than fixing because the only correct fixes are a data-semantics decision that shouldn't be made unilaterally inside this PR. Interactively-persisted rules and hand-authored rules are indistinguishable once both live in settings.permissions.allow, so there is no small, correct way to keep an interactive grant from activating the allowlist without choosing one of:

  1. Persist "Always allow" grants under a separate key that stays a pure auto-approval grant (mirrors how this PR keeps --allowed-tools / tools.allowed out of registryAllowList). Cost: new settings key + load-path merge into the auto-approval path + migration for rules users already accumulated under permissions.allow.
  2. Record provenance metadata on persisted rules and gate activation on hand-authored intent. Cost: settings-schema change.
  3. Mitigation only (startup notice naming the hidden tools + confirmation-dialog warning). Cheap, but does not stop the toolset collapse.

My lean is (1) since it matches the grant-vs-allowlist split this PR already establishes, but it changes the on-disk settings format and the public permissions contract, so it needs a maintainer sign-off. Which direction do you want? Leaving this thread open until then.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already escalated in the round-2 thread — see reply 3840449009: the chain is confirmed real at HEAD (persisting an "Always allow" rule writes settings.permissions.allow, which activates the allowlist on next restart and collapses the toolset to that one family). The remediation requires a maintainer settings data-format decision — persist interactive grants under a separate non-activating key, or gate allowlist activation behind explicit hand-authored intent — so it is not being fixed in this review round. Leaving this thread open to track that decision.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still maintainer-gated this round — no code change on this surface (the round-6 R6-1 fix in c9b670e only touches the tool_search exemption). Note: round 6's R1-8 finding reduces to the same root question — what activates the permissions.allow registry allowlist — so both threads are consolidated under the decision laid out in reply 3840449009 (separate non-activating grant key vs. provenance-gated activation vs. mitigation-only). Leaving this thread open for maintainer sign-off.

autoMode:
bareMode || safeMode ? undefined : settings.permissions?.autoMode,
},
Expand Down
116 changes: 116 additions & 0 deletions packages/core/src/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8251,6 +8251,122 @@ describe('Server Config (config.ts)', () => {
expect(wasGrepToolRegistered).toBe(false);
});

// ── #9827: permissions.allow must shrink the tool schemas sent to the model ──
it('registers only allowlisted tools when permissions.allow is set (#9827)', async () => {
const settingsAllow = [
'ReadFile',
'WriteFile',
'Edit',
'Grep',
'Glob',
'ListFiles',
'Shell',
'WebFetch',
];
const params: ConfigParameters = {
...baseParams,
useRipgrep: false,
coreTools: undefined,
// Mirrors the CLI wiring: merged allow list + the settings-sourced
// subset that activates the registry allowlist.
permissions: { allow: settingsAllow, registryAllowList: settingsAllow },
};
const config = new Config(params);
await config.initialize();

const registerToolMock = (
(await vi.importMock('../tools/tool-registry')) as {
ToolRegistry: { prototype: { registerFactory: Mock } };
}
).ToolRegistry.prototype.registerFactory;

const registered = (registerToolMock as Mock).mock.calls.map(
(call) => call[0],
) as string[];

// Allowlisted tools are registered
expect(registered).toContain(ToolNames.READ_FILE);
expect(registered).toContain(ToolNames.WRITE_FILE);
expect(registered).toContain(ToolNames.EDIT);
expect(registered).toContain(ToolNames.GREP);
expect(registered).toContain(ToolNames.GLOB);
expect(registered).toContain(ToolNames.SHELL);
expect(registered).toContain(ToolNames.WEB_FETCH);

// Unlisted built-ins are NOT registered, so their schemas are never
// sent to the model. The reporter's grammar-breaking tools must all
// be absent; non-core built-ins are gated too.
expect(registered).not.toContain(ToolNames.SEND_MESSAGE);
expect(registered).not.toContain(ToolNames.UPDATE_GOAL);
expect(registered).not.toContain(ToolNames.GET_GOAL);
expect(registered).not.toContain(ToolNames.LOOP_WAKEUP);
expect(registered).not.toContain(ToolNames.READ_MCP_RESOURCE);
expect(registered).not.toContain(ToolNames.AGENT);
expect(registered).not.toContain(ToolNames.TODO_WRITE);
expect(registered).not.toContain(ToolNames.SKILL);
// monitor stays registered: the "Shell" allow rule covers it so the
// shell tool cannot be bypassed by switching to monitor.
expect(registered).toContain(ToolNames.MONITOR);
});

it('registers the full built-in set when no permissionsAllow is set (#9827 regression guard)', async () => {
const params: ConfigParameters = {
...baseParams,
useRipgrep: false,
coreTools: undefined,
};
const config = new Config(params);
await config.initialize();

const registerToolMock = (
(await vi.importMock('../tools/tool-registry')) as {
ToolRegistry: { prototype: { registerFactory: Mock } };
}
).ToolRegistry.prototype.registerFactory;

const registered = (registerToolMock as Mock).mock.calls.map(
(call) => call[0],
) as string[];

// Without an allowlist nothing is gated at registry level
expect(registered).toContain(ToolNames.SEND_MESSAGE);
expect(registered).toContain(ToolNames.UPDATE_GOAL);
expect(registered).toContain(ToolNames.AGENT);
expect(registered).toContain(ToolNames.TODO_WRITE);
expect(registered).toContain(ToolNames.READ_FILE);
});

it('permissions.allow keeps the --exclude-tools (deny) path working (#9827)', async () => {
const settingsAllow = ['ReadFile', 'Shell'];
const params: ConfigParameters = {
...baseParams,
useRipgrep: false,
coreTools: undefined,
permissions: {
allow: settingsAllow,
registryAllowList: settingsAllow,
deny: ['Shell'],
},
};
const config = new Config(params);
await config.initialize();

const registerToolMock = (
(await vi.importMock('../tools/tool-registry')) as {
ToolRegistry: { prototype: { registerFactory: Mock } };
}
).ToolRegistry.prototype.registerFactory;

const registered = (registerToolMock as Mock).mock.calls.map(
(call) => call[0],
) as string[];

expect(registered).toContain(ToolNames.READ_FILE);
// deny wins over allowlist membership
expect(registered).not.toContain(ToolNames.SHELL);
expect(registered).not.toContain(ToolNames.SEND_MESSAGE);
});

describe('with minified tool class names', () => {
beforeEach(() => {
Object.defineProperty(
Expand Down
23 changes: 23 additions & 0 deletions packages/core/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,15 @@ export interface ConfigParameters {
allow?: string[];
ask?: string[];
deny?: string[];
/**
* The subset of `allow` that comes from `settings.permissions.allow`
* (never `--allowed-tools`, the SDK `allowedTools` param, or the
* legacy `tools.allowed` key). When it contains at least one valid
* rule, the registry-level allowlist activates: built-in tools not
* covered by any allow rule are excluded from registration, so their
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
* schemas are never sent to the model (#9827).
*/
registryAllowList?: string[];
/** Settings consumed by the AUTO approval mode classifier. */
autoMode?: AutoModeSettings;
};
Expand Down Expand Up @@ -1899,6 +1908,7 @@ export class Config {
private readonly permissionsAllow: string[];
private readonly permissionsAsk: string[];
private readonly permissionsDeny: string[];
private readonly permissionsRegistryAllowList: string[];
private readonly permissionsAutoMode: AutoModeSettings;
private readonly toolDiscoveryCommand: string | undefined;
private readonly toolCallCommand: string | undefined;
Expand Down Expand Up @@ -2242,6 +2252,8 @@ export class Config {
this.permissionsAllow = params.permissions?.allow || [];
this.permissionsAsk = params.permissions?.ask || [];
this.permissionsDeny = params.permissions?.deny || [];
this.permissionsRegistryAllowList =
params.permissions?.registryAllowList || [];
this.permissionsAutoMode = params.permissions?.autoMode ?? {};
this.toolInvocationGuard = params.toolInvocationGuard;
this.toolDiscoveryCommand = params.toolDiscoveryCommand;
Expand Down Expand Up @@ -5549,6 +5561,17 @@ export class Config {
return this.permissionsAsk;
}

/**
* Returns the allow rules that come from `settings.permissions.allow`
* only — never `--allowed-tools` / the SDK `allowedTools` param (merged
* into `getPermissionsAllow()` above) nor the legacy `tools.allowed`
* key. Consumed by `PermissionManager` to decide whether the
* registry-level allowlist is active (#9827).
*/
getRegistryAllowList(): string[] {
return this.permissionsRegistryAllowList;
}

/**
* Returns the merged deny-rules for PermissionManager.
*
Expand Down
Loading
Loading