Skip to content

Commit fa48aee

Browse files
chore(autoreview): sync reviewer-led credential checks (#133626)
1 parent 1c10f70 commit fa48aee

4 files changed

Lines changed: 88 additions & 659 deletions

File tree

‎.agents/skills/autoreview/SKILL.md‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Do not invoke Autoreview automatically before a commit, push, PR, merge, deploy,
3333
- Tools are useful in review mode. Codex receives the validated bundle in an empty workspace so ignored files and linked-worktree metadata remain unreadable; web search stays available for dependency contracts and upstream docs.
3434
- Security perspective is always included, but it should not cripple legitimate functionality. Report security findings only when the change creates a concrete, actionable risk or removes an important safety check.
3535
- Reviewer subprocesses preserve engine authentication and non-credentialed proxy variables needed by headless or restricted-network environments while stripping process-injection, Git override, and credentialed proxy values.
36-
- Immediately before every provider call, autoreview writes the exact outgoing review pack to an owner-only temporary file and scans it with TruffleHog using `verified,unknown`. It uses the installed binary with `--no-update` to disable self-update checks and attempts. The scan covers prompt and dataset inputs, untracked content, and every diff line, including deleted lines. A finding, scanner error, or missing TruffleHog binary refuses the send and names the implicated repository file when it can be resolved; credentials are never redacted and forwarded. Security-sensitive paths remain omitted. Safe large diffs are sent as one pass while they fit the aggregate prompt limit, then partitioned into complete bounded passes without truncation.
36+
- Credential checking belongs to the reviewer: the hard rules require inspection of the entire change bundle for accidentally committed credentials and require every suspected real credential to be reported as a P0 security finding without reproducing its value. The helper does not invoke an external credential scanner. Security-sensitive paths remain omitted. Safe large diffs are sent as one pass while they fit the aggregate prompt limit, then partitioned into complete bounded passes without truncation.
3737
- Regression provenance needs patch proof, not blame alone. `git log -S/-G`, `git blame`, commit subjects, and PR metadata locate candidates. Before saying `introduced by`, inspect raw parents with `git --no-replace-objects cat-file -p <sha>` and verify the implicated behavior changed in `git --no-replace-objects diff --no-ext-diff --no-textconv <raw-parent> <sha> -- <path>`; a genuine root needs raw-header proof that it has no parents.
3838
- Blame `^sha`, porcelain `boundary`, and shallow/grafted history alone are not introduction proof. `--root` can hide boundary markers; `git show` or `rev-list --parents` can make a shallow boundary look like a root. An available raw parent permits explicit comparison even at a shallow boundary; missing parents or an unverifiable patch require `unknown` with the gap. Use `carried forward` only for verified preexisting behavior and `made visible` only for a verified trigger. Apply the same bar to finding prose, summaries, and owner hints.
3939
- Keep code author, introducing PR author, merger, committer, automation trigger, and current PR author separate; none of those roles alone proves causation. Cite the verified commit/PR/date. If no PR is traceable, use the verified commit and known author identity; unknown identities stay unknown, and missing PR metadata is not a separate finding.
@@ -191,10 +191,7 @@ history and rerun. The helper does not fetch it automatically.
191191

192192
## Oversized Bundles
193193

194-
The helper validates the complete patch before partitioning it. For partitioned
195-
reviews it scans the complete frozen input first, so credentials cannot evade
196-
detection by crossing a chunk boundary. It also scans each exact outgoing review
197-
pack before sending it. A safe bundle that fits
194+
The helper validates the complete patch before partitioning it. A bundle that fits
198195
the aggregate prompt limit remains one integrated review pass. Larger bundles
199196
are split at bundle sections and file boundaries where possible; an oversized
200197
single-file block is split at line boundaries with repeated file/hunk context
@@ -211,7 +208,7 @@ batch, and every evidence byte is retained. All validated reports are merged
211208
before required-finding and exit-status checks.
212209
There is no fixed pass-count ceiling: the complete frozen input determines the
213210
finite pass sequence. The helper prints its size and pass count before running
214-
passes serially. Each pass retains the same prompt-size limit, secret scan, and
211+
passes serially. Each pass retains the same prompt-size limit and
215212
reviewer isolation; a failed pass aborts without publishing a partial verdict.
216213

217214
Preparation prints immediate phase updates and periodic elapsed time to stderr,
@@ -220,7 +217,7 @@ are separate from provider heartbeats and do not count against engine deadlines.
220217
Bundle construction captures finding membership alongside validated text; normal
221218
and dry runs reuse that record without reopening untracked files for membership.
222219

223-
Dry runs reuse capture and scanning without whole-tree integrity sweeps. Real
220+
Dry runs reuse captured inputs and prompt construction without whole-tree integrity sweeps. Real
224221
reviews retain full fresh tree hashing before bundle construction, before review,
225222
and before publication, including unrelated tracked files, nonignored untracked files, index
226223
state, and initialized submodules. Explicit prompt files and datasets also retain
@@ -375,7 +372,7 @@ The helper:
375372
- supports `codex`, `claude`, `amp`, `pi`, and `kimi`; default is `AUTOREVIEW_ENGINE` or `codex`
376373
- resolves bare `git`, `gh`, reviewer, and PowerShell shell commands from absolute `PATH` entries only, never from the reviewed checkout; explicit `--*-bin` paths are interpreted from the reviewed repository root when relative and accepted only when both the supplied path and resolved target stay outside the reviewed repository
377374
- use `--mode commit --commit <ref>` for already-committed work, especially clean `main` after landing
378-
- validates complete Git patches, scans every outgoing review pack, reviews them in one pass up to the aggregate prompt limit, and automatically uses complete bounded passes above it
375+
- validates complete Git patches, reviews them in one pass up to the aggregate prompt limit, and automatically uses complete bounded passes above it
379376
- uses branch mode for committed-only PR work, or explicit local mode with a pinned merge base for a complete PR plus dirty candidate
380377
- writes reports to stdout and optionally to `--output` or `--json-output` files; preparation progress and provider heartbeats use stderr
381378
- supports `--dry-run` (validates bundle construction, reviewer CLI resolution, and local isolation startup with version/help probes without contacting a provider; exits nonzero if any check fails), an opt-in per-reviewer wall-clock bound via `--engine-timeout-seconds`, `--prompt`, repo-relative `--prompt-file`, repo-relative `--dataset`, `--no-tools`, `--no-web-search`, repeatable Codex-only safe model/response tuning with `--codex-config key=value`, Codex-only `--codex-speed fast|flex|default`, and commit refs
@@ -419,8 +416,8 @@ The exact source filename `CredentialFile.swift` is allowed for untracked and
419416
evidence inputs only outside sensitive parent paths, matching its existing
420417
tracked-source treatment. This is not a general source-extension exemption:
421418
credential stores, credential directories, `.env`, PEM, and key files retain
422-
their exclusions. TruffleHog still scans the exact outgoing pack, including
423-
source content, deleted lines, prompts, and datasets, before every provider call.
419+
their exclusions. Reviewers inspect the source content, deleted lines, prompts,
420+
and datasets present in each outgoing pack for accidentally committed credentials.
424421

425422
## Final Report
426423

‎.agents/skills/autoreview/scripts/autoreview‎

Lines changed: 7 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,10 +1566,6 @@ def validate_git_ref(repo: Path, ref: str, label: str, *, pin: bool = False) ->
15661566
return result.strip() if pin else ref
15671567

15681568

1569-
TRUFFLEHOG_INSTALL_URL = "https://github.com/trufflesecurity/trufflehog#installation"
1570-
TRUFFLEHOG_FINDINGS_EXIT_CODE = 183
1571-
1572-
15731569
def git_bytes(
15741570
repo: Path,
15751571
*args: str,
@@ -1599,130 +1595,6 @@ def git_bytes(
15991595
return result
16001596

16011597

1602-
def safe_trufflehog_env(repo: Path) -> dict[str, str]:
1603-
env = safe_git_env(repo)
1604-
for key in (
1605-
"ALL_PROXY",
1606-
"HTTP_PROXY",
1607-
"HTTPS_PROXY",
1608-
"NO_PROXY",
1609-
"all_proxy",
1610-
"http_proxy",
1611-
"https_proxy",
1612-
"no_proxy",
1613-
):
1614-
value = os.environ.get(key)
1615-
if not value:
1616-
continue
1617-
if key.casefold() != "no_proxy" and not safe_proxy_url(value):
1618-
raise SystemExit(
1619-
f"unsafe credentialed or malformed proxy URL in {key}; "
1620-
"configure a credential-free proxy URL before running autoreview"
1621-
)
1622-
env[key] = value
1623-
return env
1624-
1625-
1626-
def review_pack_path_at_line(prompt: str, line_number: int) -> str:
1627-
current = "review pack"
1628-
pending_untracked = False
1629-
diff_header: list[str] = []
1630-
for index, line in enumerate(prompt.splitlines(), start=1):
1631-
if line.startswith("# Prompt file: "):
1632-
current = line.removeprefix("# Prompt file: ").strip() or current
1633-
elif line.startswith("# Dataset: "):
1634-
current = line.removeprefix("# Dataset: ").strip() or current
1635-
elif line == "# Untracked File":
1636-
pending_untracked = True
1637-
current = "review pack"
1638-
elif pending_untracked and line.startswith("path: "):
1639-
try:
1640-
path = json.loads(line.removeprefix("path: "))
1641-
except json.JSONDecodeError:
1642-
path = None
1643-
if isinstance(path, str) and path:
1644-
current = path
1645-
pending_untracked = False
1646-
elif line.startswith("diff --git "):
1647-
diff_header = [line]
1648-
current = "review pack"
1649-
elif diff_header and line.startswith(("--- ", "+++ ")):
1650-
diff_header.append(line)
1651-
old_path, new_path = diff_section_paths("\n".join(diff_header))
1652-
current = new_path or old_path or current
1653-
elif not diff_header and line.startswith(("--- ", "+++ ")):
1654-
path = diff_marker_path(line[4:])
1655-
if path:
1656-
current = path
1657-
elif diff_header and line.startswith("@@"):
1658-
old_path, new_path = diff_section_paths("\n".join(diff_header))
1659-
current = new_path or old_path or current
1660-
diff_header = []
1661-
if index == line_number:
1662-
return current
1663-
return current
1664-
1665-
1666-
def trufflehog_review_pack_paths(prompt: str, output: str) -> list[str]:
1667-
paths: set[str] = set()
1668-
for line in output.splitlines():
1669-
try:
1670-
finding = json.loads(line)
1671-
except json.JSONDecodeError:
1672-
continue
1673-
filesystem = (
1674-
finding.get("SourceMetadata", {})
1675-
.get("Data", {})
1676-
.get("Filesystem", {})
1677-
)
1678-
line_number = filesystem.get("line", filesystem.get("Line"))
1679-
if isinstance(line_number, int) and line_number > 0:
1680-
paths.add(review_pack_path_at_line(prompt, line_number))
1681-
return sorted(paths or {"review pack"})
1682-
1683-
1684-
def scan_outgoing_review_pack(repo: Path, prompt: str) -> None:
1685-
trufflehog_bin = find_command("trufflehog", repo)
1686-
if not trufflehog_bin:
1687-
raise SystemExit(
1688-
"refusing to send review pack: TruffleHog is required but was not found. "
1689-
f"Install it using the official instructions, then rerun autoreview: {TRUFFLEHOG_INSTALL_URL}"
1690-
)
1691-
with tempfile.TemporaryDirectory(
1692-
prefix="autoreview-pack-scan.",
1693-
dir=safe_temp_root(repo),
1694-
) as tempdir:
1695-
pack_path = Path(tempdir) / "review-pack.txt"
1696-
pack_path.write_bytes(prompt.encode("utf-8"))
1697-
pack_path.chmod(0o600)
1698-
result = run(
1699-
[
1700-
trufflehog_bin,
1701-
"filesystem",
1702-
str(pack_path),
1703-
"--json",
1704-
"--no-color",
1705-
"--results=verified,unknown",
1706-
"--fail",
1707-
"--fail-on-scan-errors",
1708-
"--no-update",
1709-
],
1710-
Path(tempdir),
1711-
check=False,
1712-
env=safe_trufflehog_env(repo),
1713-
)
1714-
if result.returncode == TRUFFLEHOG_FINDINGS_EXIT_CODE:
1715-
paths = trufflehog_review_pack_paths(prompt, result.stdout)
1716-
raise SystemExit(
1717-
"refusing to send review pack: TruffleHog found credentials in "
1718-
+ ", ".join(paths)
1719-
)
1720-
if result.returncode != 0:
1721-
raise SystemExit(
1722-
"refusing to send review pack: TruffleHog could not complete the scan"
1723-
)
1724-
1725-
17261598
def bounded(text: str, limit: int = 180_000) -> str:
17271599
if len(text) <= limit:
17281600
return text
@@ -3218,6 +3090,7 @@ def render_review_prompt(
32183090
- Report EVERY distinct actionable defect in this single pass, ordered most severe first. Each review round costs the caller a full fix-test-review cycle; withholding a known defect until a later round wastes one.
32193091
- Before returning, sweep the bundle once more for independent defects in other files or failure modes that you may have stopped scanning for after an earlier find.
32203092
- Include security findings: injection, secret leaks, authz/authn bypass, path traversal, unsafe deserialization, unsafe filesystem or shell use, privacy leaks, and credential handling.
3093+
- Inspect the entire change bundle for accidentally committed credentials or secrets, including API keys, access tokens, passwords, private keys, and credential-bearing URLs. Report every suspected real credential as a P0 security finding at the smallest file/line location that demonstrates it, without reproducing the credential value. Do not flag obvious placeholders or inert test fixtures unless they are usable credentials or create a concrete risk.
32213094
- Do not reject legitimate functionality merely because it touches shell, filesystem, network, auth, or sensitive data. Report a security finding only when the patch creates a concrete exploitable risk, removes an important safety check, or lacks validation at a trust boundary.
32223095
- Security-sensitive bundle material may be redacted or omitted before review. Continue reviewing the material that is present. A redaction notice is not itself a defect and does not prove either safety or vulnerability in the omitted material.
32233096
- For each finding, use the smallest file/line location that demonstrates the issue.
@@ -3368,17 +3241,9 @@ def prepare_review_prompts(
33683241
datasets: list[ReviewDataset],
33693242
max_prompt_bytes: int,
33703243
) -> list[str]:
3371-
prompts = build_review_prompts(
3244+
return build_review_prompts(
33723245
repo, target, target_ref, bundle, extra_prompt, datasets, max_prompt_bytes,
33733246
)
3374-
if len(prompts) > 1:
3375-
# A credential can span a partition boundary. Scan the complete frozen
3376-
# input before any send, in addition to each exact outgoing pack.
3377-
scan_outgoing_review_pack(repo, render_review_prompt(
3378-
current_branch(repo), target, target_ref, ReviewChunk(bundle),
3379-
extra_prompt, render_datasets(datasets),
3380-
))
3381-
return prompts
33823247

33833248

33843249
def write_json_temp(data: dict[str, Any], temp_root: Path) -> Path:
@@ -5951,9 +5816,8 @@ def dry_run_preflight(
59515816
and pass the same repo-relative/existence checks the real run applies
59525817
via capture_evidence_inputs, that the assembled prompt(s) pass
59535818
the same aggregate-size/partition and truncation-refusal checks the
5954-
real run applies via build_review_prompts/ensure_reviewer_input_complete
5955-
and the same fail-closed TruffleHog scan of each exact outgoing prompt
5956-
used by a real run, and that each configured reviewer's CLI binary resolves and
5819+
real run applies via build_review_prompts/ensure_reviewer_input_complete,
5820+
and that each configured reviewer's CLI binary resolves and
59575821
its configuration (including, for Kimi, load_kimi_review_config and
59585822
validate_kimi_runtime_auth_sources, and for Claude, the tool
59595823
inventory) is one a real run would actually accept. Returns the
@@ -5990,7 +5854,7 @@ def dry_run_preflight(
59905854
# inputs a real run rejects once combined.
59915855
if bundle_ok and inputs_ok:
59925856
try:
5993-
with PreparationProgress("bundle/evidence preparation and scan"):
5857+
with PreparationProgress("bundle/evidence preparation"):
59945858
input_truncated = captured.truncated or evidence.truncated
59955859
if reviewers:
59965860
ensure_reviewer_input_complete(reviewers[0], input_truncated)
@@ -5999,8 +5863,6 @@ def dry_run_preflight(
59995863
repo, target, target_ref, captured.text, threshold_extra_prompt,
60005864
evidence.datasets, max_prompt_bytes_for_reviewers(reviewers),
60015865
)
6002-
for prompt in prompts:
6003-
scan_outgoing_review_pack(repo, prompt)
60045866
with PreparationProgress("evidence verification"):
60055867
verify_evidence(repo, evidence.files)
60065868
print("prompt: OK", flush=True)
@@ -6036,8 +5898,7 @@ def run_reviewer(
60365898
evidence: list[EvidenceFile] | None = None,
60375899
) -> dict[str, Any]:
60385900
ensure_reviewer_input_complete(args, input_truncated)
6039-
with PreparationProgress("outgoing pack scan and evidence verification"):
6040-
scan_outgoing_review_pack(repo, prompt)
5901+
with PreparationProgress("evidence verification"):
60415902
verify_evidence(repo, evidence or [])
60425903
raw = run_engine(args, repo, prompt)
60435904
report = extract_json(raw)
@@ -6211,7 +6072,7 @@ def main_impl() -> int:
62116072
evidence = capture_evidence_inputs(args, repo)
62126073
with PreparationProgress("initial source snapshot") as progress:
62136074
review_source_snapshot = source_tree_snapshot(repo, progress)
6214-
with PreparationProgress("bundle/evidence preparation and scan"):
6075+
with PreparationProgress("bundle/evidence preparation"):
62156076
captured = build_bundle(repo, target, target_ref, args.commit)
62166077
if target == "commit":
62176078
target_ref = args.commit

0 commit comments

Comments
 (0)