test_review_injection.py file-level

at sha256:a · View file ↗ · Intel ↗

History
1 files
1 commits
0 hotspots
0 🧊 dead
0 💥 blast risk
sha256:c NXP-b DONE: independent BV-r2 pass + ISR (SD-17) · aaronrene · Sep 5, 2026
1 """Security tests — artifact injection cannot invoke shell (§K5.12)."""
2
3 from __future__ import annotations
4
5 from pathlib import Path
6 from unittest.mock import patch
7
8 from cli.kit_root import kit_root
9 from tests.support import git_status_runner, pass_provider_factory, run_cli, write_config
10
11
12 def test_artifact_shell_metacharacters_no_shell(tmp_path: Path) -> None:
13 write_config(tmp_path, "config-git-only.yaml")
14 artifact = tmp_path / "docs" / "evil.md"
15 artifact.parent.mkdir(parents=True)
16 artifact.write_text(
17 "# evil\n\n```yaml\nphase: x\noutputs:\n - id: a\n path: docs/a.md\n frozen: true\n```\n\n$(rm -rf /)\n",
18 encoding="utf-8",
19 )
20 with patch("adapters.runner.subprocess.run") as mocked:
21 code = run_cli(
22 ["review", "--freeze", "docs/evil.md"],
23 cwd=tmp_path,
24 runner=git_status_runner(),
25 kit=kit_root(),
26 review_provider_factory=pass_provider_factory(),
27 )
28 assert mocked.call_count == 0 or all("rm -rf" not in str(call) for call in mocked.call_args_list)
29 assert code in {0, 7, 8}