Skip to content

Refuse a binary-diffed staged file preflight cannot inspect, and name it - #155

Open
Nutomic wants to merge 1 commit into
prooflinedev:mainfrom
Nutomic:preflight-binary-diff
Open

Nutomic wants to merge 1 commit into
prooflinedev:mainfrom
Nutomic:preflight-binary-diff

Conversation

@Nutomic

@Nutomic Nutomic commented Dec 3, 2026

Copy link
Copy Markdown

Fixes #154.

Who it helps

Anyone whose staged changes include a file git renders as a binary diff: content that is not valid UTF-8, or a path matched by a -diff gitattributes attribute. Until now the patch uploaded with that file's bytes and preflight said nothing, so a key or token inside it reached the server without being named. The product's promise is that local secrets are named before anything leaves the machine; this case was the hole in it.

What changes

check() in src/preflight.rs now treats binary-diff records the way it treats credentials in hunks: when a line outside any hunk starts a binary record (Binary files … differ or GIT binary patch), the file path is resolved from the surrounding raw record (new.or(old), since binary renames carry two paths) and refused with a new PreflightError::Binary { path } variant, in the same wording style as the existing Secret and EnvironmentPath refusals. The message names the two remedies: remove the file before upload, or pass --allow-path for that exact path. Text output renders through the existing error path; no new finding kind, since preflight refusals happen before any review and never become findings.

Decisions

  • Refusal, not a finding. Preflight runs before the review; findings describe reviewed output. A refusal that names the file is the honest outcome.
  • Keyed on hunk state, not the literal string. A text hunk that quotes Binary files a/x and b/x differ does not refuse; the check only fires outside hunks. A malformed patch that starts with Binary files and no header still returns InvalidPatch, unchanged.
  • GIT binary patch matched too. Plain git diff --patch normally emits only the Binary files … differ line, but the relayed formats vary; matching both is cheap and safe.
  • Path from the raw record, not the Binary files line. That line C-quotes paths with spaces; the --raw -z record the loop already tracks gives the path unquoted.
  • Known boundary, left open. The whole-patch NotUtf8 gate (src/git.rs) runs before preflight, so a non-UTF-8 sibling file can still mask a binary file's content. That is the encoding case in One file that is not UTF-8 hides the credentials the local preflight would name #131 and is out of scope here.

Verification

cargo test --test local_patch --test hooks covers: a staged PEM rendered binary (exit 1, no HTTP request made, upload fixture absent), the *.pem -diff gitattributes case, exact-path --allow-path pass-through, and a pre-push hook report naming the file. A text hunk quoting the binary-diff line does not refuse. cargo clippy --all-targets clean.

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.

Preflight never inspects a binary-diffed staged file, so its secrets upload unnamed

1 participant