From e5d1e7d9b6d0d8641bbbdae673e3cb3b39f90c91 Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 02:19:16 +0100 Subject: [PATCH 1/2] Isolate fake reviewer tests from host credentials Co-Authored-By: Codex --- tests/test_runners.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/test_runners.py b/tests/test_runners.py index 9e07d096..95774b05 100644 --- a/tests/test_runners.py +++ b/tests/test_runners.py @@ -17,7 +17,7 @@ import pytest -from loopzero import sandbox +from loopzero import runners, sandbox from loopzero.runners import ( REVIEW_SCHEMA, RunnerAuthFailed, @@ -113,8 +113,17 @@ def _bwrap_argv(log: Path) -> list[str]: @pytest.fixture(autouse=True) -def fake_bwrap(fake_tool, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path: - for name in ("ANTHROPIC_API_KEY", "CLAUDE_CODE_OAUTH_TOKEN", "OPENAI_API_KEY"): +def fake_bwrap(fake_tool, tmp_path: Path, tmp_path_factory, monkeypatch: pytest.MonkeyPatch) -> Path: + # Keep reviewer state outside tmp_path, which many tests mount as the checkout. + home = tmp_path_factory.mktemp("reviewer-home") + monkeypatch.setenv("HOME", str(home)) + for name in ( + "CODEX_HOME", + "CLAUDE_CONFIG_DIR", + "CLAUDE_SECURESTORAGE_CONFIG_DIR", + *runners.CLAUDE_AUTH_ENV, + *runners.CODEX_AUTH_ENV, + ): monkeypatch.delenv(name, raising=False) log = tmp_path / "review-bwrap.argv" fake_tool("bwrap", FAKE_BWRAP.format(log=log)) From ffdcdbf34d3e1937ac6baec071b26ed5bb283078 Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 02:25:42 +0100 Subject: [PATCH 2/2] Redact credential-shaped values in public review findings Architecture-Review: unchanged; publication and recovery still use the same GitHub payload and original finding identities. Co-Authored-By: Codex --- src/loopzero/github.py | 10 +++++----- tests/test_review_recovery.py | 30 +++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/loopzero/github.py b/src/loopzero/github.py index 9ecaffd1..66723735 100644 --- a/src/loopzero/github.py +++ b/src/loopzero/github.py @@ -119,8 +119,8 @@ class Readiness: _read_scope: ContextVar[tuple[float, str | None, bool] | None] = ContextVar("github_reads", default=None) _api_error_diagnostics: ContextVar[bool] = ContextVar("github_api_error_diagnostics", default=False) _HTTP_STATUS_RE = re.compile(r"^HTTP/\S+\s+(\d{3})(?:\s+(.*))?$", re.IGNORECASE) -_GITHUB_TOKEN_RE = re.compile( - r"\b(?:github_pat_[A-Za-z0-9_]+|gh[pousr]_[A-Za-z0-9_]{10,})\b" +_CREDENTIAL_TOKEN_RE = re.compile( + r"\b(?:github_pat_[A-Za-z0-9_]+\b|gh[pousr]_[A-Za-z0-9_]{10,}\b|sk-[A-Za-z0-9_-]{8,})" ) @@ -204,7 +204,7 @@ def _redact_tokens(value: str, token: str = "") -> str: value = re.sub(r"(?i)\b(authorization)\s*[:=]\s*" r"(?:(?:basic|bearer|token)\s+)?[^\s,;]+", r"\1=[REDACTED]", value) value = re.sub(r"(?i)\bBearer\s+[^\s,;]+", "Bearer [REDACTED]", value) - value = _GITHUB_TOKEN_RE.sub("[REDACTED]", value) + value = _CREDENTIAL_TOKEN_RE.sub("[REDACTED]", value) value = re.sub(r"(?i)\b(access_token|auth_token|token)\s*[:=]\s*" r"[^\s,;]+", r"\1=[REDACTED]", value) value = re.sub(r"(?i)(https?://[^?\s]+)\?[^\s]+", r"\1?[REDACTED]", value) @@ -715,7 +715,7 @@ def finding_marker(severity: str, head_sha: str, finding: Finding) -> str: def _comment_body(f: Finding, head_sha: str, prefix: str = "") -> str: - text = f"{prefix}**{f.severity}: {f.title}**\n\n{f.body}".rstrip() + text = prefix + _CREDENTIAL_TOKEN_RE.sub("[REDACTED]", f"**{f.severity}: {f.title}**\n\n{f.body}").rstrip() if f.severity in BLOCKING: return f"{finding_marker(f.severity, head_sha, f)}\n{text}" return text @@ -767,7 +767,7 @@ def _review_body(result: ReviewResult, unplaced: list[Finding], prefix: str = "" lines.extend(_review_settings_lines(result, include_configured=settings_layout == "current")) if unplaced: lines.append("\nFindings without a file location:\n") - lines += [f"- **{f.severity}**: {f.title} — {f.body}".rstrip(" —") for f in unplaced] + lines += [_CREDENTIAL_TOKEN_RE.sub("[REDACTED]", f"- **{f.severity}**: {f.title} — {f.body}".rstrip(" —")) for f in unplaced] return "\n".join(lines) + _review_transcript(result, legacy_display) diff --git a/tests/test_review_recovery.py b/tests/test_review_recovery.py index 40e02dba..2ac8f0e8 100644 --- a/tests/test_review_recovery.py +++ b/tests/test_review_recovery.py @@ -24,14 +24,16 @@ def lost_reply(wt, gh, fake_bin, monkeypatch, *, kind, verdict, interrupted=False, - mutate=None, timeout=False): + mutate=None, timeout=False, findings=None): history = [] if kind == "delta": history = [rev(head_of(wt), "primary")] (wt / "feature.py").write_text("print('fixed')\n") git(wt, "commit", "-qam", "repair") - head = support.prepare_review(wt, gh, fake_bin, history=history, post_id=17, - payload=APPROVE if verdict == 0 else CHANGES) + payload = APPROVE if verdict == 0 else CHANGES + if findings is not None: + payload = {**payload, "findings": findings} + head = support.prepare_review(wt, gh, fake_bin, history=history, post_id=17, payload=payload) reviewer = fake_bin / "claude" reviewer.write_text(reviewer.read_text().replace( "#!/bin/sh\n", f'#!/bin/sh\nprintf "run\\n" >> "{fake_bin}/claude.runs"\n')) @@ -199,6 +201,28 @@ def read(endpoint): assert len([c for c in gh.calls if "--input" in c]) == 1 +def test_repost_recovers_review_with_redacted_findings(wt, gh, fake_bin, monkeypatch, capsys): + title = "Rotate sk-ant-FAKE0123" + findings = [ + {"severity": "important", "path": "feature.py", "line": 1, + "title": title, "body": "Remove sk-proj-Fake_only-0123 from settings."}, + {"severity": "suggestion", "path": None, "line": None, + "title": "Replace ghp_FAKE0123456789", "body": "See sk-FakeToken0123 in the log."}, + ] + head = lost_reply(wt, gh, fake_bin, monkeypatch, kind="primary", verdict=5, + interrupted=True, findings=findings) + assert run(capsys, "review")[0] == 130 + payload = support.posted_review(gh) + assert "**suggestion**: Replace [REDACTED] — See [REDACTED] in the log." in payload["body"] + comment, = payload["comments"] + assert (comment["path"], comment["line"], comment["side"]) == ("feature.py", 1, "RIGHT") + stable_id = github.finding_id(head, "feature.py", 1, title) + assert comment["body"].splitlines()[0].endswith(f"severity=important head={head} id={stable_id} -->") + assert "**important: Rotate [REDACTED]**\n\nRemove [REDACTED] from settings." in comment["body"] + assert run(capsys, "review", "--repost")[0] == 5 + assert_single_publication(gh, fake_bin) + + def test_interrupted_explicit_repost_recovers_repost_body(wt, gh, fake_bin, monkeypatch, capsys): head = lost_reply(wt, gh, fake_bin, monkeypatch, kind="primary", verdict=5, interrupted=True) original = github._api