fix(git): preserve trailing CR when splitting raw commit/tag objects - #871
Open
kanywst wants to merge 1 commit into
Open
fix(git): preserve trailing CR when splitting raw commit/tag objects#871kanywst wants to merge 1 commit into
kanywst wants to merge 1 commit into
Conversation
SplitCommit, SplitTag and checkUniqueHeaders read lines with bufio.ScanLines, which drops a trailing '\r'. git doesn't, so what we split isn't the bytes git hashed. A commit and its trailing-'\r' twin are separate objects that split to the same payload, so one signature verifies for both. And a line that is just '\r' reads as blank and ends the header scan, so ValidateCommit and ValidateTag miss a duplicate tree or object header placed after it. Split on '\n' and keep the '\r'. Signed-off-by: kanywst <niwatakuma@icloud.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SplitCommit,SplitTagandcheckUniqueHeaders(pkg/git/rawobj.go) read lines withbufio.Scanner's defaultScanLines, which drops a trailing\r. git-core doesn't, so what gitsign splits isn't the bytes git hashed.A commit and its trailing-
\rtwin are separate objects that split to the samePayload, so one signature verifies for both. And a line that is just\rreads as blank atrawobj.go:459and ends the header scan, soValidateCommitmisses a duplicatetreeplaced after it:git and go-git both keep reading headers past that line, so the duplicate is in the header section for everyone except the validator. Without the
\r, the same object is rejected.Fix splits on
\nand keeps the\r. The four new test cases fail before it.No exploit that I can find: a trailing
\ris the only edit that leaves the payload unchanged, and the validator feeds the attest path only. Happy to take this private instead if you'd rather.