diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fefc470a..ce0c19a94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### Unreleased maintenance fixes +### Fixes +* Backport scoped `allowed-tools` grant handling from #768: recognize declarations such as `Bash(git:*)`, preserve spaces and commas inside scopes, and keep malformed grants or embedded tool names from declaring shell capability. Command restrictions remain intact in the manifest. +--- ### 2.13.3 (Unreleased) ### Security and integrity fixes * Prevent baseline and recursive reports from overwriting primary and child inputs, including aliases. (#924, #938) diff --git a/src/skillspector/allowed_tools.py b/src/skillspector/allowed_tools.py new file mode 100644 index 000000000..6ce752a70 --- /dev/null +++ b/src/skillspector/allowed_tools.py @@ -0,0 +1,124 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Split and validate Agent Skills ``allowed-tools`` grants. + +A string ``allowed-tools`` value lists grants separated by commas or by +whitespace. Each grant is a bare tool name (``Read``) or a scoped grant in the +``Tool(specifier)`` form (``Bash(git status:*)``, ``Read(./docs, notes.md)``). +As in Claude Code's permission rule syntax, parentheses inside the specifier +are literal characters, not nested structure: ``Bash(echo '(')`` is a complete +grant. A separator inside a specifier belongs to the specifier, so a scoped +grant is kept whole and its specifier text is never read as another grant. +""" + +from __future__ import annotations + +import re +from collections.abc import Iterator + +# Tool names longer than this are not looked up. +MAX_ALLOWED_TOOL_NAME_CHARS = 64 + +_TOKENS = re.compile(r"[(),]|\s+") +_NON_WHITESPACE = re.compile(r"\S") +# Same tool-name alphabet as the settings permission-rule check in +# ``nodes/analyzers/bundled_execution_surface.py`` (``_permission_rule_is_valid``). +# Unlike that check, the specifier's parentheses do not have to balance. +_TOOL_NAME = re.compile(r"[A-Za-z0-9_*.-]+") + + +def _ends_specifier(value: str, end: int) -> bool: + """Return whether a ``)`` ending at ``end`` is followed by a separator or the end.""" + return end == len(value) or value[end] == "," or value[end].isspace() + + +def _separators(value: str) -> Iterator[re.Match[str]]: + """Yield the commas and whitespace runs of ``value`` that lie outside a specifier. + + A ``(`` outside a specifier opens one. Inside it, ``(`` and ``)`` are + literal, except that a ``)`` followed by a comma, whitespace or the end of + the value closes it. + """ + in_specifier = False + for match in _TOKENS.finditer(value): + token = match.group() + if in_specifier: + if token == ")" and _ends_specifier(value, match.end()): + in_specifier = False + elif token == "(": + in_specifier = True + elif token != ")": + yield match + + +def iter_allowed_tools_entries(value: str) -> Iterator[str]: + """Yield the stripped entries of a string ``allowed-tools`` value. + + A comma outside any specifier selects the comma-separated form; otherwise + entries are separated by whitespace. Only separators outside a specifier + split. A specifier runs from a ``(`` to the first ``)`` that is followed by + a comma, whitespace or the end of the value, and any ``(`` or ``)`` in + between is literal. So ``"Bash(git status:*) Read"`` and + ``"Bash(echo '(') Read"`` each yield two entries, and + ``"Read(./docs Bash(notes).md)"`` and ``"Read(./a, b)"`` each stay one + entry. A specifier whose own text has a ``)`` followed by a separator + cannot be written in a string value; the list form keeps it whole. An + unclosed ``(`` keeps the rest of the value in its entry, which + :func:`allowed_tool_grant_name` rejects. + + Entries are produced lazily. As with ``str.split``, the comma form yields + an empty entry between adjacent commas and the whitespace form yields no + empty entries; callers skip empty entries. + """ + comma_form = any(match.group() == "," for match in _separators(value)) + start = 0 + for match in _separators(value): + if comma_form and match.group() != ",": + continue + entry = value[start : match.start()].strip() + if entry or comma_form: + yield entry + start = match.end() + entry = value[start:].strip() + if entry or comma_form: + yield entry + + +def allowed_tool_grant_name(entry: str) -> str | None: + """Return the tool name of a complete ``allowed-tools`` grant, else ``None``. + + A complete grant is either a bare tool name or ``Tool(specifier)``, where + the specifier is everything between the first ``(`` and the final ``)``, + which must be the last character, and is not blank. Parentheses inside the + specifier are literal, so ``Bash(echo '(')`` and ``Bash(echo ')')`` are + complete. Incomplete grants such as ``Bash(``, ``Bash(notes`` or + ``Bash(echo '('`` and blank ones such as ``Bash()`` return ``None``, so + they name no tool. Names longer than :data:`MAX_ALLOWED_TOOL_NAME_CHARS` + also return ``None``. + """ + entry = entry.strip() + # Bound the search so a long specifier is not scanned for the name. + paren = entry.find("(", 0, MAX_ALLOWED_TOOL_NAME_CHARS + 1) + if paren == -1 and len(entry) > MAX_ALLOWED_TOOL_NAME_CHARS: + return None + name = entry if paren == -1 else entry[:paren] + if _TOOL_NAME.fullmatch(name) is None: + return None + if paren == -1: + return name + if not entry.endswith(")") or _NON_WHITESPACE.search(entry, paren + 1, len(entry) - 1) is None: + return None + return name diff --git a/src/skillspector/nodes/analyzers/mcp_least_privilege.py b/src/skillspector/nodes/analyzers/mcp_least_privilege.py index 1033bbfe4..83ea990fc 100644 --- a/src/skillspector/nodes/analyzers/mcp_least_privilege.py +++ b/src/skillspector/nodes/analyzers/mcp_least_privilege.py @@ -22,6 +22,7 @@ from dataclasses import dataclass, field from pathlib import Path +from skillspector.allowed_tools import allowed_tool_grant_name, iter_allowed_tools_entries from skillspector.inspection_ledger import ( InspectionLedgerEvent, LedgerOutcome, @@ -248,18 +249,17 @@ def _normalize_allowed_tools( Accepts the list form (``[Bash, Read]``), the comma-separated string form (``"Bash, Read"``), and the space-separated string form - (``"Bash Read"``). Anything else yields an empty list. + (``"Bash Read"``). Separators inside a ``Tool(specifier)`` scope do not + split, so ``"Bash(git status:*) Read"`` and ``"Bash(echo '(') Read"`` each + yield two entries. Anything else yields an empty list. """ tools: list[str] = [] if isinstance(value, list): candidates = iter(value) elif isinstance(value, str): - if "," in value: - # A bounded split prevents a comma-dense declaration from creating an - # arbitrarily large temporary list before the analyzer can stop it. - candidates = iter(value.split(",", _MAX_DECLARATION_VALUES)) - else: - candidates = iter(value.split(None, _MAX_DECLARATION_VALUES)) + # Entries are produced lazily, so a comma-dense declaration stops at the + # limit below without building an arbitrarily large temporary list. + candidates = iter_allowed_tools_entries(value) else: return tools @@ -348,7 +348,8 @@ def _map_permissions_to_categories( return categories -# Tool name → capability category (Claude / Agent Skills tool names, case-insensitive exact match) +# Tool name → capability category (Claude / Agent Skills tool names, case-insensitive exact match +# on the name of a well-formed bare or ``Tool(specifier)`` grant) _TOOL_TO_CAPABILITY: dict[str, str] = { "bash": "shell", "execute": "shell", @@ -371,14 +372,23 @@ def _map_allowed_tools_to_categories( tools: list[str], budget: _LeastPrivilegeBudget | None = None, ) -> set[str]: - """Map Agent Skills ``allowed-tools`` tool names to capability category names.""" + """Map Agent Skills ``allowed-tools`` tool names to capability category names. + + Scoped grants in the ``Tool(specifier)`` form, such as ``Bash(git:*)`` or + ``WebFetch(domain:example.com)``, map by their tool name, so a narrower + grant covers the same category as the bare tool. Parentheses inside the + specifier are literal, so ``Bash(echo '(')`` maps to ``shell``. Incomplete + or blank grants such as ``Bash(``, ``Bash(notes`` or ``Bash()`` map to no + category. + """ categories: set[str] = set() for tool in tools: if budget is not None: budget.check_runtime("SKILL.md") - if len(tool) > 64: + name = allowed_tool_grant_name(tool) + if name is None: continue - cat = _TOOL_TO_CAPABILITY.get(tool.lower().strip()) + cat = _TOOL_TO_CAPABILITY.get(name.lower()) if cat: categories.add(cat) return categories diff --git a/src/skillspector/nodes/build_context.py b/src/skillspector/nodes/build_context.py index a4faaba27..002bb4275 100644 --- a/src/skillspector/nodes/build_context.py +++ b/src/skillspector/nodes/build_context.py @@ -35,6 +35,7 @@ import yaml +from skillspector.allowed_tools import iter_allowed_tools_entries from skillspector.artifacts import ( ArtifactDisposition, ArtifactRecord, @@ -2350,27 +2351,16 @@ def _string_list(value: object) -> list[str]: manifest["triggers"] = _string_list(data.get("triggers", [])) manifest["permissions"] = _string_list(data.get("permissions", [])) # `allowed-tools` (Agent Skills standard) — accept list, comma string, or space-separated string. + # Separators inside a `Tool(specifier)` scope belong to the scope, so + # `Bash(git status:*) Read` stays two grants. allowed_tools = data.get("allowed-tools", []) if isinstance(allowed_tools, str): - if "," in allowed_tools: - tools: list[str] = [] - cursor = 0 - while cursor <= len(allowed_tools): - _check() - separator = allowed_tools.find(",", cursor) - if separator < 0: - separator = len(allowed_tools) - item = allowed_tools[cursor:separator].strip() - if item: - tools.append(_scalar_text(item)) - if separator == len(allowed_tools): - break - cursor = separator + 1 - manifest["allowed-tools"] = tools - else: - manifest["allowed-tools"] = [ - _scalar_text(t) for t in allowed_tools.split() if t.strip() - ] + tools: list[str] = [] + for item in iter_allowed_tools_entries(allowed_tools): + _check() + if item: + tools.append(_scalar_text(item)) + manifest["allowed-tools"] = tools elif isinstance(allowed_tools, list): manifest["allowed-tools"] = [ item.strip() for item in _string_list(allowed_tools) if item.strip() diff --git a/tests/nodes/test_build_context.py b/tests/nodes/test_build_context.py index f208cd14c..816f523bb 100644 --- a/tests/nodes/test_build_context.py +++ b/tests/nodes/test_build_context.py @@ -1276,6 +1276,65 @@ def test_build_context_parses_allowed_tools_single_space_string(tmp_path: Path) assert result["manifest"]["allowed-tools"] == ["Bash"] +@pytest.mark.parametrize( + ("declaration", "expected"), + [ + pytest.param( + "Bash(git status:*) Read", + ["Bash(git status:*)", "Read"], + id="space_inside_scope", + ), + pytest.param( + "Bash(git status:*), Read", + ["Bash(git status:*)", "Read"], + id="comma_string", + ), + pytest.param( + "Read(./docs Bash(notes).md)", + ["Read(./docs Bash(notes).md)"], + id="nested_parens_inside_scope", + ), + pytest.param( + "Read(./docs, Bash(notes).md)", + ["Read(./docs, Bash(notes).md)"], + id="comma_inside_scope", + ), + pytest.param( + "Bash(git status:*) Read(./a, b)", + ["Bash(git status:*)", "Read(./a, b)"], + id="comma_only_inside_scope_keeps_space_form", + ), + pytest.param( + "Bash(echo '(') Read", ["Bash(echo '(')", "Read"], id="literal_open_paren_in_scope" + ), + pytest.param( + "Bash(echo ')') Read", ["Bash(echo ')')", "Read"], id="literal_close_paren_in_scope" + ), + pytest.param( + "Bash(echo '('), Read", + ["Bash(echo '(')", "Read"], + id="comma_string_literal_open_paren_in_scope", + ), + pytest.param( + "Bash(echo ')'), Read", + ["Bash(echo ')')", "Read"], + id="comma_string_literal_close_paren_in_scope", + ), + ], +) +def test_build_context_keeps_scoped_allowed_tools_whole( + tmp_path: Path, declaration: str, expected: list[str] +) -> None: + """Separators inside a `Tool(specifier)` scope belong to the scope.""" + (tmp_path / "SKILL.md").write_text( + f"---\nname: deployer\ndescription: deploys services\nallowed-tools: {declaration}\n---\n", + encoding="utf-8", + ) + state: SkillspectorState = {"skill_path": str(tmp_path)} + result = build_context(state) + assert result["manifest"]["allowed-tools"] == expected + + def test_build_context_inventories_excluded_executable_descendants(tmp_path: Path) -> None: """Excluded trees retain bounded inventory and executable coverage evidence.""" (tmp_path / "SKILL.md").write_text("# Skill\n", encoding="utf-8") diff --git a/tests/test_mcp_least_privilege.py b/tests/test_mcp_least_privilege.py index 082ce8d4d..46e5352b8 100644 --- a/tests/test_mcp_least_privilege.py +++ b/tests/test_mcp_least_privilege.py @@ -20,6 +20,7 @@ import re from pathlib import Path +import pytest import yaml from skillspector.nodes.analyzers import mcp_least_privilege @@ -342,6 +343,250 @@ def test_allowed_tools_fully_covered_no_lp1(self): f"Bash covers shell capability — no LP1 expected, got: {[f.rule_id for f in findings]}" ) + @pytest.mark.parametrize( + "allowed_tools", + [ + pytest.param(["Bash(git:*)"], id="list_scoped"), + pytest.param("Bash(git:*) Bash(jq:*) Read", id="space_string_scoped"), + pytest.param("Bash(git status:*) Read", id="space_string_scoped_with_space"), + pytest.param("Bash(git status:*), Read", id="comma_string_scoped"), + pytest.param(["Bash(notes).md)"], id="list_literal_close_paren_inside_scope"), + ], + ) + def test_allowed_tools_scoped_bash_covers_shell_no_lp1(self, allowed_tools): + """A scoped grant such as ``Bash(git:*)`` (the Agent Skills spec example + form) declares the Bash tool, so it covers the shell capability just + like the broader bare ``Bash`` grant does.""" + state = _make_state("mcp_underdeclared_skill") + state["manifest"]["permissions"] = None + state["manifest"]["allowed-tools"] = allowed_tools + state["file_cache"]["skill.py"] = "import subprocess\nsubprocess.run(['git', 'status'])\n" + state["component_metadata"] = [ + {"path": "skill.py", "type": "python", "executable": True, "lines": 2, "size_bytes": 60} + ] + state["components"] = ["skill.py"] + result = mcp_least_privilege.node(state) + findings = result["findings"] + lp1_findings = [f for f in findings if f.rule_id == "LP1" and "shell" in f.message] + assert lp1_findings == [], ( + "Scoped Bash covers shell capability — no LP1 expected, got: " + f"{[(f.rule_id, f.message) for f in findings]}" + ) + + @pytest.mark.parametrize( + "allowed_tools", + [ + pytest.param(["Bash(echo '(')"], id="list_literal_open_paren"), + pytest.param(["Bash(echo ')')"], id="list_literal_close_paren"), + pytest.param("Bash(echo '(') Read", id="space_string_literal_open_paren"), + pytest.param("Bash(echo ')') Read", id="space_string_literal_close_paren"), + pytest.param("Bash(echo '('), Read", id="comma_string_literal_open_paren"), + pytest.param("Bash(echo ')'), Read", id="comma_string_literal_close_paren"), + ], + ) + def test_allowed_tools_bash_scope_with_literal_parens_covers_shell_no_lp1(self, allowed_tools): + """Parentheses inside a specifier are literal, as in Claude Code's + permission rule syntax, so ``Bash(echo '(')`` is a complete Bash grant + and covers the shell capability.""" + state = _make_state("mcp_underdeclared_skill") + state["manifest"]["permissions"] = None + state["manifest"]["allowed-tools"] = allowed_tools + state["file_cache"]["skill.py"] = ( + 'import subprocess\nsubprocess.run(["echo", "("], check=True)\n' + ) + state["component_metadata"] = [ + {"path": "skill.py", "type": "python", "executable": True, "lines": 2, "size_bytes": 60} + ] + state["components"] = ["skill.py"] + result = mcp_least_privilege.node(state) + findings = result["findings"] + lp1_findings = [f for f in findings if f.rule_id == "LP1" and "shell" in f.message] + assert lp1_findings == [], ( + "Bash(echo ...) covers shell capability — no LP1 expected, got: " + f"{[(f.rule_id, f.message) for f in findings]}" + ) + + @pytest.mark.parametrize( + "allowed_tools", + [ + pytest.param(["Bash(echo '('"], id="list_unclosed_scope_with_literal_open_paren"), + pytest.param(["Bash(echo ')'"], id="list_unclosed_scope_with_literal_close_paren"), + pytest.param("Bash(echo '( Read", id="space_string_unclosed_scope"), + pytest.param("Bash(echo '(', Read", id="comma_string_unclosed_scope"), + ], + ) + def test_allowed_tools_incomplete_bash_scope_with_literal_parens_still_lp1(self, allowed_tools): + """A literal parenthesis does not complete a grant: without a final + ``)`` the outer ``Bash(`` grant is incomplete and covers nothing.""" + state = _make_state("mcp_underdeclared_skill") + state["manifest"]["permissions"] = None + state["manifest"]["allowed-tools"] = allowed_tools + state["file_cache"]["skill.py"] = ( + 'import subprocess\nsubprocess.run(["echo", "("], check=True)\n' + ) + state["component_metadata"] = [ + {"path": "skill.py", "type": "python", "executable": True, "lines": 2, "size_bytes": 60} + ] + state["components"] = ["skill.py"] + result = mcp_least_privilege.node(state) + findings = result["findings"] + lp1_findings = [f for f in findings if f.rule_id == "LP1" and "shell" in f.message] + assert len(lp1_findings) == 1, ( + "No complete Bash grant is declared — LP1 for shell expected, got: " + f"{[(f.rule_id, f.message) for f in findings]}" + ) + + def test_allowed_tools_scoped_non_shell_tool_still_lp1(self): + """A scoped grant only covers its own tool: ``Read(./docs/**)`` does not + cover the shell capability.""" + state = _make_state("mcp_underdeclared_skill") + state["manifest"]["permissions"] = None + state["manifest"]["allowed-tools"] = ["Read(./docs/**)"] + state["file_cache"]["skill.py"] = "import subprocess\nsubprocess.run(['git', 'status'])\n" + state["component_metadata"] = [ + {"path": "skill.py", "type": "python", "executable": True, "lines": 2, "size_bytes": 60} + ] + state["components"] = ["skill.py"] + result = mcp_least_privilege.node(state) + findings = result["findings"] + lp1_findings = [f for f in findings if f.rule_id == "LP1" and "shell" in f.message] + assert len(lp1_findings) == 1, ( + f"Read(...) does not cover shell — LP1 expected, got: {[f.rule_id for f in findings]}" + ) + + def test_map_allowed_tools_uses_tool_name_before_specifier(self): + categories = mcp_least_privilege._map_allowed_tools_to_categories( + ["Bash(git:*)", "WebFetch(domain:example.com)", "Read(./docs/**)", "Edit(src/**)"] + ) + assert categories == {"shell", "network", "file_read", "file_write"} + + @pytest.mark.parametrize( + "allowed_tools", + [ + pytest.param("Read(./docs Bash(notes).md)", id="space_string_bash_inside_read_scope"), + pytest.param("Read(./docs, Bash(notes).md)", id="comma_string_bash_inside_read_scope"), + pytest.param(["Read(./docs Bash(notes).md)"], id="list_bash_inside_read_scope"), + pytest.param(["Bash("], id="list_unclosed_bash_scope"), + pytest.param(["Bash(notes"], id="list_unterminated_bash_scope"), + pytest.param("Bash(notes Read", id="space_string_unterminated_bash_scope"), + pytest.param(["Bash()"], id="list_empty_bash_scope"), + ], + ) + def test_allowed_tools_malformed_or_nested_bash_still_lp1(self, allowed_tools): + """Only a complete grant names a tool. Text inside another grant's + scope, such as ``Bash(notes)`` in ``Read(./docs Bash(notes).md)``, and + incomplete grants such as ``Bash(`` do not declare Bash, so they do not + cover the shell capability.""" + state = _make_state("mcp_underdeclared_skill") + state["manifest"]["permissions"] = None + state["manifest"]["allowed-tools"] = allowed_tools + state["file_cache"]["skill.py"] = "import subprocess\nsubprocess.run(['git', 'status'])\n" + state["component_metadata"] = [ + {"path": "skill.py", "type": "python", "executable": True, "lines": 2, "size_bytes": 60} + ] + state["components"] = ["skill.py"] + result = mcp_least_privilege.node(state) + findings = result["findings"] + lp1_findings = [f for f in findings if f.rule_id == "LP1" and "shell" in f.message] + assert len(lp1_findings) == 1, ( + "No complete Bash grant is declared — LP1 for shell expected, got: " + f"{[(f.rule_id, f.message) for f in findings]}" + ) + + @pytest.mark.parametrize( + ("allowed_tools", "expected"), + [ + pytest.param( + "Bash(git status:*) Read", + ["Bash(git status:*)", "Read"], + id="space_inside_scope", + ), + pytest.param( + "Bash(git status:*), Read", + ["Bash(git status:*)", "Read"], + id="comma_string", + ), + pytest.param( + "Read(./docs Bash(notes).md)", + ["Read(./docs Bash(notes).md)"], + id="nested_parens_inside_scope", + ), + pytest.param( + "Read(./docs, Bash(notes).md)", + ["Read(./docs, Bash(notes).md)"], + id="comma_inside_scope", + ), + pytest.param( + "Bash(git status:*) Read(./a, b)", + ["Bash(git status:*)", "Read(./a, b)"], + id="comma_only_inside_scope_keeps_space_form", + ), + pytest.param("Bash(notes Read", ["Bash(notes Read"], id="unclosed_scope_keeps_rest"), + pytest.param("Bash) Read", ["Bash)", "Read"], id="stray_close_paren"), + pytest.param( + "Bash(echo '(') Read", ["Bash(echo '(')", "Read"], id="literal_open_paren" + ), + pytest.param( + "Bash(echo ')') Read", ["Bash(echo ')')", "Read"], id="literal_close_paren" + ), + pytest.param( + "Bash(echo '('), Read", + ["Bash(echo '(')", "Read"], + id="comma_string_literal_open_paren", + ), + pytest.param( + "Bash(echo ')'), Read", + ["Bash(echo ')')", "Read"], + id="comma_string_literal_close_paren", + ), + pytest.param( + "Bash(echo ')') Read(./a, b)", + ["Bash(echo ')')", "Read(./a, b)"], + id="literal_close_paren_then_comma_inside_scope", + ), + pytest.param( + "Bash(echo ') x') Read", + ["Bash(echo ')", "x')", "Read"], + id="close_paren_before_space_ends_scope", + ), + ], + ) + def test_normalize_allowed_tools_keeps_scoped_grants_whole(self, allowed_tools, expected): + assert mcp_least_privilege._normalize_allowed_tools(allowed_tools) == expected + + def test_map_allowed_tools_ignores_malformed_grants(self): + malformed = [ + "Bash(", + "Bash(notes", + "Bash()", + "Bash( )", + "Bash(echo '('", + "Bash(echo ')'", + "Bash)", + "(Bash)", + "Bash (git:*)", + "Read(./docs Bash(notes).md", + ] + assert mcp_least_privilege._map_allowed_tools_to_categories(malformed) == set() + # A scope may itself contain parentheses. + assert mcp_least_privilege._map_allowed_tools_to_categories( + ["Read(./docs Bash(notes).md)", "Edit(./notes (old)/**)"] + ) == {"file_read", "file_write"} + + @pytest.mark.parametrize( + "grant", + [ + pytest.param("Bash(echo '(')", id="literal_open_paren"), + pytest.param("Bash(echo ')')", id="literal_close_paren"), + pytest.param("Bash(notes).md)", id="literal_close_paren_mid_scope"), + pytest.param("Bash(a)(b)", id="literal_parens_mid_scope"), + ], + ) + def test_map_allowed_tools_treats_scope_parens_as_literal(self, grant): + """The specifier runs from the first ``(`` to the final ``)`` and its + parentheses are literal, so these are complete Bash grants.""" + assert mcp_least_privilege._map_allowed_tools_to_categories([grant]) == {"shell"} + class TestLP4OverDeclared: def test_over_declared_detected(self):