Skip to content

Commit ca3067a

Browse files
authored
Merge pull request #840 from chrisknvidia/feat/christopherk/registry-option-validation
Reject unsupported skill options in registry mode
2 parents 95a52d8 + f7ad068 commit ca3067a

4 files changed

Lines changed: 172 additions & 1 deletion

File tree

‎README.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ are rejected. This option requires `--mcp-registry` and is separate from the
228228
finding-suppression `--baseline`: it never suppresses findings or changes risk
229229
scores, and it does not fetch or execute listed server endpoints.
230230

231+
Registry mode rejects skill-only controls such as `--use-shipped-baseline`,
232+
`--transitive`, `--transitive-depth`, `--transitive-allow-prefix`, and
233+
`--transitive-deny-prefix` with exit code 2, including an explicitly supplied
234+
default depth (`--transitive-depth 1`). Omit these options for registry scans.
235+
231236
### Suppressing False Positives (baseline)
232237

233238
Suppress known/accepted findings so the risk score reflects only un-triaged

‎src/skillspector/cli.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from urllib.parse import quote
3838

3939
import typer
40+
from click.core import ParameterSource
4041
from langchain_core.runnables import RunnableConfig
4142
from rich.console import Console
4243
from rich.progress import BarColumn, Progress, SpinnerColumn, TextColumn, TimeElapsedColumn
@@ -474,6 +475,7 @@ def _multi_skill_limitation_events(
474475

475476
@app.command()
476477
def scan(
478+
ctx: typer.Context,
477479
input_path: Annotated[
478480
str,
479481
typer.Argument(
@@ -706,11 +708,18 @@ def scan(
706708
or show_suppressed
707709
or yara_rules_dir is not None
708710
or min_coverage is not None
711+
or use_shipped_baseline
712+
or transitive_enabled
713+
or transitive_allow_prefix
714+
or transitive_deny_prefix
715+
# Even an explicitly supplied default depth requests an unsupported option.
716+
or ctx.get_parameter_source("transitive_depth") not in (None, ParameterSource.DEFAULT)
709717
):
710718
err_console.print(
711719
"[red]Error:[/red] --mcp-registry cannot be combined with "
712720
"--recursive, --baseline, --show-suppressed, --yara-rules-dir, "
713-
"or --min-coverage"
721+
"--min-coverage, --use-shipped-baseline, --transitive, "
722+
"--transitive-depth, --transitive-allow-prefix, or --transitive-deny-prefix"
714723
)
715724
raise typer.Exit(code=2)
716725
if format != FormatChoice.json:

‎tests/unit/test_cli.py‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,6 +1754,69 @@ def test_cli_mcp_registry_rejects_skill_only_flags(tmp_path: Path, flag: str) ->
17541754
assert "cannot be combined" in result.output
17551755

17561756

1757+
@pytest.mark.parametrize(
1758+
"flags",
1759+
[
1760+
["--use-shipped-baseline"],
1761+
["--transitive"],
1762+
["--transitive-depth", "1"],
1763+
["--transitive-depth", "0"],
1764+
["--transitive-depth", "-1"],
1765+
["--transitive-depth", "2"],
1766+
["--transitive-allow-prefix", "https://example.com/"],
1767+
["--transitive-deny-prefix", "https://example.com/"],
1768+
["--transitive-allow-prefix", ""],
1769+
["--transitive-deny-prefix", "not-a-prefix"],
1770+
["--transitive", "--transitive-depth", "2", "--use-shipped-baseline"],
1771+
],
1772+
)
1773+
def test_cli_mcp_registry_rejects_ignored_options_before_scanning(
1774+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, flags: list[str]
1775+
) -> None:
1776+
payload = tmp_path / "registry.json"
1777+
payload.write_text('{"servers": []}', encoding="utf-8")
1778+
output = tmp_path / "report.json"
1779+
output.write_text("previous report", encoding="utf-8")
1780+
scan_registry = MagicMock(return_value={"findings": [], "risk_score": 0})
1781+
monkeypatch.setattr(cli, "scan_registry", scan_registry)
1782+
1783+
result = runner.invoke(
1784+
app,
1785+
[
1786+
"scan",
1787+
str(payload),
1788+
"--mcp-registry",
1789+
"--format",
1790+
"json",
1791+
"--output",
1792+
str(output),
1793+
*flags,
1794+
],
1795+
)
1796+
1797+
assert result.exit_code == 2
1798+
assert "cannot be combined" in result.stderr
1799+
assert flags[0] in result.stderr
1800+
assert result.stdout == ""
1801+
assert output.read_text(encoding="utf-8") == "previous report"
1802+
scan_registry.assert_not_called()
1803+
1804+
1805+
def test_cli_mcp_registry_rejects_configured_transitive_depth(tmp_path: Path) -> None:
1806+
payload = tmp_path / "registry.json"
1807+
payload.write_text('{"servers": []}', encoding="utf-8")
1808+
1809+
result = runner.invoke(
1810+
app,
1811+
["scan", str(payload), "--mcp-registry", "--format", "json"],
1812+
default_map={"scan": {"transitive_depth": 1}},
1813+
)
1814+
1815+
assert result.exit_code == 2
1816+
assert "--transitive-depth" in result.stderr
1817+
assert result.stdout == ""
1818+
1819+
17571820
def test_cli_scan_missing_baseline_exits_2(tmp_path: Path) -> None:
17581821
"""scan with a --baseline pointing at a missing file exits with code 2."""
17591822
(tmp_path / "SKILL.md").write_text("# Hi", encoding="utf-8")

‎tests/unit/test_cli_subprocess.py‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,100 @@ def _write_skill(path: Path, body: str = "# Helper\n\nFormat a table.\n") -> Pat
6363
return path
6464

6565

66+
@pytest.mark.parametrize(
67+
"flags",
68+
[
69+
["--use-shipped-baseline"],
70+
["--transitive"],
71+
["--transitive-depth", "1"],
72+
["--transitive-depth", "2"],
73+
["--transitive-allow-prefix", "https://example.com/"],
74+
["--transitive-deny-prefix", "https://example.com/"],
75+
],
76+
)
77+
def test_registry_unsupported_options_stop_before_input_or_output_access(
78+
tmp_path: Path, flags: list[str]
79+
) -> None:
80+
output = tmp_path / "report.json"
81+
output.write_text("previous report", encoding="utf-8")
82+
83+
result = _run_cli(
84+
"scan",
85+
str(tmp_path / "missing-registry.json"),
86+
"--mcp-registry",
87+
"--format",
88+
"json",
89+
"--output",
90+
str(output),
91+
*flags,
92+
)
93+
94+
assert result.returncode == 2
95+
assert "cannot be combined" in result.stderr
96+
assert flags[0] in result.stderr
97+
assert result.stdout == ""
98+
assert output.read_text(encoding="utf-8") == "previous report"
99+
100+
101+
def test_registry_default_options_still_allow_snapshot_comparison(tmp_path: Path) -> None:
102+
source = tmp_path / "registry.json"
103+
source.write_text(
104+
json.dumps(
105+
{
106+
"servers": [
107+
{
108+
"server": {
109+
"name": "example/notes",
110+
"version": "1.0.0",
111+
"repository": {
112+
"url": "https://github.com/example/notes",
113+
"source": "github",
114+
},
115+
"packages": [
116+
{
117+
"registryType": "npm",
118+
"identifier": "example-notes",
119+
"version": "1.0.0",
120+
"fileSha256": "a" * 64,
121+
"transport": {"type": "stdio"},
122+
}
123+
],
124+
},
125+
"_meta": {
126+
"io.modelcontextprotocol.registry/official": {"status": "active"}
127+
},
128+
}
129+
]
130+
}
131+
),
132+
encoding="utf-8",
133+
)
134+
previous = tmp_path / "previous.json"
135+
initial = _run_cli(
136+
"scan", str(source), "--mcp-registry", "--format", "json", "--output", str(previous)
137+
)
138+
assert initial.returncode == 0, initial.stderr
139+
previous_bytes = previous.read_bytes()
140+
141+
compared = _run_cli(
142+
"scan",
143+
str(source),
144+
"--mcp-registry",
145+
"--format",
146+
"json",
147+
"--mcp-registry-compare",
148+
str(previous),
149+
)
150+
151+
assert compared.returncode == 0, compared.stderr
152+
payload = json.loads(compared.stdout)
153+
assert payload["mcp_registry"] is True
154+
assert payload["server_count"] == 1
155+
assert payload["risk_score"] == 0
156+
assert payload["comparison"]["unchanged_count"] == 1
157+
assert previous.read_bytes() == previous_bytes
158+
159+
66160
@pytest.mark.parametrize("verbose", [False, True])
67161
def test_recursive_json_stdout_is_one_complete_report(tmp_path: Path, verbose: bool) -> None:
68162
collection = tmp_path / "collection"

0 commit comments

Comments
 (0)