test_honesty_security.py
python
sha256:a78e7e5a8740e03315f325d19edeb3aa1b306b3337d04abbaa9a9e0f3bbeb7a1
docs: MuseHub-first before ISR #74 — staging solidify NEXT
Human
1 day ago
| 1 | """Security tests for honesty module path discipline.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import json |
| 6 | |
| 7 | from tests.support import load_honesty_config, load_honesty_entry, run_cli, seed_honesty_repo |
| 8 | from cli.kit_root import kit_root |
| 9 | from tests.support import git_status_runner |
| 10 | from tools.honesty.ledger import show_entries |
| 11 | from tools.honesty.status import HonestyStatusOptions, run_honesty_status |
| 12 | |
| 13 | |
| 14 | def test_path_escape_artifact_refused(repo_root) -> None: |
| 15 | config = load_honesty_config(repo_root) |
| 16 | result = run_honesty_status( |
| 17 | config=config, |
| 18 | repo_root=repo_root, |
| 19 | options=HonestyStatusOptions(hook="board_done", artifact="../outside.txt"), |
| 20 | ) |
| 21 | assert result.exit_code == 4 |
| 22 | |
| 23 | |
| 24 | def test_path_escape_append_file_refused(repo_root) -> None: |
| 25 | config = load_honesty_config(repo_root) |
| 26 | outside = repo_root.parent / "escaped.json" |
| 27 | outside.write_text("{}", encoding="utf-8") |
| 28 | from tools.honesty.ledger import parse_append_body |
| 29 | |
| 30 | body, code, _ = parse_append_body( |
| 31 | repo_root=repo_root, |
| 32 | file_path=str(outside), |
| 33 | stdin_text=None, |
| 34 | ) |
| 35 | assert code == 4 |
| 36 | |
| 37 | |
| 38 | def test_roles_file_content_cannot_inject_roles(repo_root) -> None: |
| 39 | config = load_honesty_config(repo_root) |
| 40 | roles = repo_root / "roles.yaml" |
| 41 | roles.write_text("roles:\n hacker: admin\n", encoding="utf-8") |
| 42 | cfg = repo_root / ".overseer" / "config.yaml" |
| 43 | import yaml |
| 44 | |
| 45 | data = yaml.safe_load(cfg.read_text(encoding="utf-8")) |
| 46 | data["honesty"]["roles_file"] = "roles.yaml" |
| 47 | cfg.write_text(yaml.safe_dump(data), encoding="utf-8") |
| 48 | from adapters.config import load_config |
| 49 | |
| 50 | config = load_config(cfg) |
| 51 | body = load_honesty_entry(repo_root, "verdict-producer.json") |
| 52 | from tools.honesty.ledger import append_entry |
| 53 | from tools.honesty.types import LedgerAppendOptions |
| 54 | |
| 55 | result = append_entry( |
| 56 | config=config, |
| 57 | repo_root=repo_root, |
| 58 | options=LedgerAppendOptions(kind="verdict", body=body), |
| 59 | ) |
| 60 | assert result.exit_code == 23 |
| 61 | |
| 62 | |
| 63 | def test_evidence_notes_injection_not_executed(tmp_path) -> None: |
| 64 | seed_honesty_repo(tmp_path) |
| 65 | artifact_hash = __import__("tests.support", fromlist=["honesty_artifact_hash"]).honesty_artifact_hash(tmp_path) |
| 66 | payload = { |
| 67 | "actor_role": "verifier", |
| 68 | "actor_session_id": "v1", |
| 69 | "artifact_sha256": artifact_hash, |
| 70 | "passed": True, |
| 71 | "evidence": { |
| 72 | "reexecuted": ["verify-step:x"], |
| 73 | "notes": "$(rm -rf /); __import__('os').system('echo pwned')", |
| 74 | }, |
| 75 | } |
| 76 | path = tmp_path / "payload.json" |
| 77 | path.write_text(json.dumps(payload), encoding="utf-8") |
| 78 | code = run_cli( |
| 79 | ["ledger", "append", "--kind", "verdict", "--file", "payload.json"], |
| 80 | cwd=tmp_path, |
| 81 | runner=git_status_runner(), |
| 82 | kit=kit_root(), |
| 83 | ) |
| 84 | assert code == 0 |
| 85 | show = show_entries(config=load_honesty_config(tmp_path), repo_root=tmp_path, last_n=5) |
| 86 | joined = "\n".join(show.stdout_lines) |
| 87 | assert "__import__('os').system" in joined |
| 88 | assert "rm -rf" in joined |
File History
2 commits
sha256:a78e7e5a8740e03315f325d19edeb3aa1b306b3337d04abbaa9a9e0f3bbeb7a1
docs: MuseHub-first before ISR #74 — staging solidify NEXT
Human
1 day ago
sha256:4671b7f787ddbe63ced31c895b688c77ab495653b65a730b423329f26b3c1439
feat: K1-P1 complete — agent provenance, build-verification…
Sonnet 4.6
patch
53 days ago