Skip to content

Name a credential in a local patch before refusing it as a whole - #132

Open
ammartahamohamedy wants to merge 1 commit into
prooflinedev:mainfrom
ammar-taha-dev:fix/preflight-before-patch-refusals
Open

ammartahamohamedy wants to merge 1 commit into
prooflinedev:mainfrom
ammar-taha-dev:fix/preflight-before-patch-refusals

Conversation

@ammartahamohamedy

@ammartahamohamedy ammartahamohamedy commented Nov 30, 2026 •

Copy link
Copy Markdown

Fixes #131

Problem

git::diff refuses a whole patch that has text that isn't UTF-8, is over 5 MiB or has over 3,000 files, before preflight::check runs. The refusal then names only its reason, never a credential in the same patch. In the pre-push hook, one Latin-1 file in the range is enough: under warn the push proceeds and the token goes out unmentioned; under block the reason reads like an encoding problem and the hook offers --no-verify.

Fix

  • Refusals keep the patch. NotUtf8, TooLarge and TooManyFiles now carry it as a Refused, read lossily (String::from_utf8_lossy): each invalid byte becomes U+FFFD, so lines and paths keep their places. Paths that aren't UTF-8 are read the same way and refused as NotUtf8, as before. Refused has no public accessor for the text, and its Debug omits it.
  • The preflight reads it first. preflight::check_refused runs the usual check on a refused patch. hooks::ready and review_local report a credential or .env path if there is one, and the original refusal otherwise. --allow-path works as before: allowing the exact path leaves the refusal.
  • Nothing refused is uploaded, and no message's wording changes: a patch with a credential now gets the preflight's existing message instead of the refusal's.
  • InvalidDiff is now checked before the size limits, since a refused patch only helps the preflight if its paths can be read.

The pre-push hook, with a token and a Latin-1 file in the range:

- Proofline could not review main: the local changes include text that is not UTF-8, which Proofline cannot review
+ Proofline could not review main: local patch contains a GitHub token at "settings.py":1 (new line); remove it before upload, or pass --allow-path for that exact path
  The push proceeds without a complete review.

#121 maps the same three variants to a --path hint in review_local. The variants now carry data, so its TooLarge(_) | TooManyFiles(_) | NotUtf8 pattern becomes TooLarge(..) | TooManyFiles(..) | NotUtf8(_). That's a compile error rather than a silent change, and both edits touch the same local_changes(...).await in review_local. I'm happy to rebase on whichever lands first.

Tests (written first; the three integration tests failed with the refusal messages before the fix)

Test What it checks
a_refused_push_still_names_the_credential_it_carries (new, tests/hooks.rs) Pre-push of three branches. Latin-1 + token: the token is named at line 2, no encoding message. Latin-1 only: "not UTF-8". A 7 MiB file + token: the token is named at line 600,001. Exit 0 under warn, no uploads
a_patch_that_is_not_utf8_names_its_credential_before_http (new, tests/local_patch.rs) review names the token at line 2. With --allow-path settings.py, it refuses as "not UTF-8". No requests, index untouched
local_selection_uploads_only_selected_bytes_and_refuses_before_http (extended) A token in one of 3,001 files is named instead of the file-count refusal
a_refused_patch_keeps_lossy_text_and_paths_for_the_preflight (new, git.rs unit) A commit with a Latin-1 line and a non-UTF-8 path, built through the index so any file system can run it. range_changes returns NotUtf8 holding U+FFFD text and path with the same lines, and the error's Debug doesn't contain the token
size_refusals_keep_the_credential_for_the_preflight (new, git.rs unit) Two-file --raw -z --patch output, with a token at line 2 of the second file. It's read with small limits standing in for 5 MiB and 3,000 files. Both TooLarge and TooManyFiles refuse, check_refused names the token at "settings.py":2, and neither error's Debug contains it. No Git or disk involved: diff now hands its output to read_diff, which takes the limits

Mutation checks: each of these makes a new test fail:

  • TooLarge keeping no patch (hooks.rs test, large branch);
  • TooLarge and TooManyFiles keeping no patch (size_refusals_… unit test);
  • review_local skipping check_refused (both local_patch.rs tests).

End to end, with the built binary: the reproduction in #131 names "settings.py":1 instead of the encoding, under warn and under block.

Checks

  • cargo fmt --check: ✅
  • cargo clippy --locked -- -D warnings: clean on the lib, the bins and every integration test. --all-targets stops at the 2 errors main already has on Windows (src/agent/tests.rs).
  • cargo test --locked: the changed and new tests pass. On Windows, the same 9 tests fail as on main, outside this change (mcp, agent install, update, added_context_deleted_and_quoted_content_refuses_before_http on a file name Windows forbids, and a_push_reviews_the_branches_it_updates_and_skips_tags_and_deletions on a Windows push URL).
  • cargo deny check: no dependency changes.
  • Fork CI: check and windows passed on ammar-taha-dev/proofline-cli#2.

Proofline review log

Fork review PR: ammar-taha-dev/proofline-cli#2. Rounds capped at 2.

Round Finding What I made of it Outcome
1 None ("Proofline review finished: no new findings") Nothing to act on No changes; one round was enough

The prompts below are the ones that drove this implementation; the investigation, reproduction and fix scope were done before them and aren't included.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

One file that is not UTF-8 hides the credentials the local preflight would name

1 participant