//nefariousplan

CVE-2026-44309: Gitsign Verified a Re-encoding. The Re-encoding Was Not the Object Git-core Ships.

vendor

pattern

cve

proof of concept

gitsign verify was added to gitsign on March 23, 2023, in pull request #262, because git verify-commit did not check Rekor identity claims. The new command's first work item was a call to repo.CommitObject(h), which parsed the raw bytes of the commit through go-git. Its next work item was c.EncodeWithoutSignature(c2), which re-encoded the parsed structure with the signature header removed. The bytes that came out the other side of that round trip, not the bytes git-core ships, were what the cryptographic signature check ran over. Every commit, for three years, one month, and thirteen days. That gap is CVE-2026-44309.

Gitsign verified a re-encoding

The pre-patch internal/commands/verify/verify.go is short enough to print whole. It ran unchanged from March 2023 to commit 3c84d87 on May 6, 2026:

c, err := repo.CommitObject(*h)
if err != nil {
    return fmt.Errorf("error reading commit object: %w", err)
}

sig := []byte(c.PGPSignature)
p, _ := pem.Decode(sig)
if p == nil || p.Type != "SIGNED MESSAGE" {
    return fmt.Errorf("unsupported signature type")
}

c2 := new(plumbing.MemoryObject)
if err := c.EncodeWithoutSignature(c2); err != nil {
    return err
}
r, err := c2.Reader()
// ...
data, err := io.ReadAll(r)
// ...
summary, err := v.Verify(ctx, data, sig, true)

The flow has three stages. repo.CommitObject(*h) parses the raw bytes from the object database through go-git's loose-object parser into a structured *object.Commit. c.EncodeWithoutSignature(c2) walks that structure back through go-git's encoder and serializes it without the gpgsig header. data is the round-trip output. v.Verify(ctx, data, sig, true) runs the cryptographic check over data.

When git-core verifies a signed commit, it reads the raw bytes from the object database, strips the gpgsig header by walking the byte stream, and runs the signature check over what is left. The bytes git-core hashes for verification are byte-for-byte the bytes stored on disk, minus one specific substring. Whoever signed the commit signed those bytes.

Gitsign did not do that. Gitsign parsed the bytes through go-git, then re-serialized them, then verified the re-serialization. If go-git's Decode and EncodeWithoutSignature composed to the identity on every commit-valid input, the two paths would produce the same bytes. They do not.

go-git is last-wins. git-core is first-wins.

A commit object's header section is a list of name SP value LF lines. The tree, parent (when only one parent), author, and committer fields are conventionally singleton headers. The serialization spec does not say what to do if a singleton header appears twice. git-core's parser, in commit.c, takes the first occurrence and ignores the rest. go-git's loose-object parser, in plumbing/object/commit.go, takes the last occurrence and overwrites earlier ones as it iterates.

Both implementations accept the input. Both consider the second header a no-op for the structure they build. They simply build opposite structures.

For a well-formed commit with one of each header, the two parsers agree byte-for-byte. For a commit with two tree headers, the two parsers diverge on the entire commit. git-core resolves the commit to the first tree; go-git resolves it to the second. The commit hash, computed by git's hasher over the raw object bytes, is fixed by the bytes and does not care which tree any parser picked. The two parsers share the same commit identity. They do not share the commit's contents.

Gitsign's verify path sat on top of go-git. The bytes that reached the signature check were EncodeWithoutSignature(Decode(raw)). For a malformed commit with two tree headers, Decode kept the second tree and discarded the first; EncodeWithoutSignature emitted a clean, single-tree commit body with the second tree only. The signature check ran over those bytes. A signature made over a canonical single-tree form of the same logical commit verified perfectly.

What the forgery looks like

The patch lands a regression test, TestDuplicateTreeTrustConfusion in internal/gitsign/invalid_object_test.go, that constructs the attack end-to-end. The setup signs what Alice intends to sign:

const (
    legitTree    = "b333504b8cf3d9c314fed2cc242c5c38e89534a5"
    attackerTree = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
    author       = "author Alice <[email protected]> 1700000000 +0000"
    committer    = "committer Alice <[email protected]> 1700000000 +0000"
    message      = "legit commit\n"
)

// Canonical commit body, what Alice intended to sign. One tree header,
// message "legit commit".
canonical := []byte(fmt.Sprintf("tree %s\n%s\n%s\n\n%s",
    legitTree, author, committer, message))

resp, err := signature.Sign(ctx, id, canonical, signature.SignOptions{
    Detached:     true,
    Armor:        true,
    IncludeCerts: 0,
})

Alice signs tree <legit>\nauthor ...\ncommitter ...\n\nlegit commit\n. The signature attests to those bytes. Nothing about the signing operation is unusual.

The attacker assembles a commit Alice did not write:

malformedRaw := []byte(fmt.Sprintf(
    "tree %s\ntree %s\n%s\n%s\n%s\n%s",
    attackerTree, legitTree,
    author, committer,
    indent("gpgsig ", string(resp.Signature)),
    message,
))

Two tree headers. The attacker's tree first. Alice's legitimate tree second. Alice's signature, taken verbatim from her signing operation, inserted as a gpgsig continuation block. The bytes are written to the object database; git's hash of those bytes is the commit identifier. The repository now contains a commit attributed to Alice, signed by Alice's certificate, whose hash points at attacker-controlled tree contents.

gitsign verify <hash> against the malformed commit: go-git parses the two trees and keeps the second, Alice's legit tree; EncodeWithoutSignature emits a clean single-tree commit body whose tree is Alice's legit one; the signature check runs over those bytes. The result matches what Alice signed. Verification passes.

git verify-commit <hash> against the same commit: git-core strips gpgsig from the raw bytes and runs the signature check over what remains, which still has two tree headers. The signature does not cover two-tree bytes. git-core's verification fails. But when git-core reads the commit for any other purpose, git log, git checkout, git diff, it parses the same bytes and picks the first tree. The attacker's tree.

A user who runs gitsign verify and trusts the "verified" status, then runs git checkout on the same commit, checks out the attacker's tree from a commit gitsign just confirmed was signed by Alice.

The signature was over bytes nobody else uses

The regression test asserts both halves of the disagreement in code:

t.Run("signature is a genuine forgery against the re-encoded form", func(t *testing.T) {
    reencoded := reencodeViaGoGit(t, malformedRaw)
    if _, err := gv.Verify(ctx, reencoded, resp.Signature, true); err != nil {
        t.Fatalf("expected signature to verify over re-encoded bytes: %v", err)
    }
})

t.Run("fix: signature fails to verify against the raw malformed bytes", func(t *testing.T) {
    c, err := git.SplitCommit(bytes.NewReader(malformedRaw))
    if err != nil { t.Fatalf("SplitCommit: %v", err) }
    if _, err := gv.Verify(ctx, c.Payload, c.Gpgsig, true); err == nil {
        t.Fatalf("expected signature verification to fail against malformed raw bytes")
    }
})

The first subtest reproduces what gitsign did in production for three years. It pushes the malformed commit through go-git, hands the re-encoded output to the verifier, and asserts that the signature verifies. The test fails if the signature does not verify, because then the PoC is not actually a forgery. The patch author writes that assertion so the second subtest's pass condition cannot be vacuous. The first subtest is a snapshot of the bug, codified as a positive assertion: this is what happens when you feed the verifier the re-encoded form.

The second subtest hands the verifier c.Payload, the output of SplitCommit, which is the raw object-database bytes with the signature header removed and nothing else. The signature was made over single-tree bytes. The verifier now sees two-tree bytes. The cryptographic check fails. The forgery is rejected.

The same signature, same commit hash, same go-git, same verifier code path, two different payloads, two different verification outcomes. The bug was never in the cryptography. The bug was that the cryptography was given the wrong payload.

The patch admits the design

The new file pkg/git/rawobj.go introduces SplitCommit, the replacement for the parse-and-re-encode pipeline. The comment block above it is unusually direct:

// SplitCommit parses the raw bytes of a commit object (object-database form,
// without the "commit <len>\0" prefix) into payload + signatures.
//
// It operates purely on the raw bytes, mirroring what git-core feeds to its
// signature verifier, and does not go through go-git's object parser.
//
// The trust-confusion class of attack (GHSA-7rmh-48mx-2vwc) relied on gitsign
// re-encoding through go-git before verification, which normalized away
// duplicate headers and let a signature over the canonical form verify
// against attacker-controlled raw bytes. Verifying directly over the raw
// bytes blocks that: any structural divergence between what was signed and
// what's stored makes the signature fail to verify cryptographically.
// Consequently, SplitCommit doesn't reject merely "weird but git-valid"
// objects (e.g. duplicate tree headers); the signature check below is what
// catches them.

The last sentence is the design admission. The new parser is not trying to be a strict commit parser. It does not reject duplicate tree headers. It does not try to be more careful about git's object format than git-core is. It walks the bytes, separates the gpgsig block from the rest, and hands the rest to the cryptographic check unmodified. The cryptographic check is the only opinion that matters about whether the bytes were signed by the named identity, and the cryptographic check sees the same bytes git-core sees.

This is the correct shape for a signature verifier. The bytes the consumer will act on are the bytes the signature must cover. If a verifier transforms those bytes before the cryptographic check, the verifier is implicitly attesting to a different artifact than the consumer reads. The commit message on 3c84d87 names the class:

An attacker can craft a commit or tag whose raw bytes hash to one set of contents under git-core but re-encode through go-git to a different signed payload, letting a legitimate signature verify against attacker-controlled bytes.

The verifier was canonicalizing before verifying. The fix removes the canonicalization. The bytes the verifier sees and the bytes git-core sees are now the same bytes.

The parser was not the only one

The companion fix landed nine days later as commit 03848e9 on May 15, 2026, titled "Reject malformed objects in attest predicate generation." Its commit message:

Bump go-git to v5.19.0 (which fixes the loose-object parser to match git-core's first-wins semantics on duplicate singleton headers) and add ValidateCommit/ValidateTag checks so CommitStatement and TagStatement refuse objects with duplicate singleton headers.

go-git's loose-object parser was last-wins. git-core's parser was first-wins. Both libraries had been shipping to large user populations, parsing the same object format, with opposite resolutions on duplicate singleton headers, for the entire lifetime of go-git's commit parser. CVE-2026-44309 is filed against gitsign because gitsign is where the trust boundary lived. The release notes that record what the underlying parser was doing differently are go-git's.

Every consumer of go-git that built a security decision on the structure of a parsed commit, the tree it pointed at, the author it named, the parents it claimed, was vulnerable to the same primitive against any check that compared the parsed structure to anything else's view of the same bytes. The CVE record names one consumer. The parser was the same for the rest.

Canonicalize before verify

The Canonicalize Before Verify pattern, the verifier-side cousin of the better-known Gate Before Canonicalize, names what happened. A signature verifier that runs its cryptographic check over a transformation of the input has implicitly bound the signature to the transformation's output rather than to the input. If any other consumer reads the input through a different parser, that consumer is reading bytes the verifier never attested to. The fix is to verify against the bytes a downstream consumer will act on, and to let downstream consumers parse those bytes however they like; the cryptographic check is the only structural enforcement the verifier needs.

PR #262, the one that added gitsign verify in March 2023, opened with this rationale:

Previously we relied on git verify-commit for commit verification. While this did check that the signature was valid and it exists in rekor, it did not check whether the identity was what was expected, because Git does not give controls over this via the commit signature interface.

gitsign verify exists to do strictly more checking than git verify-commit does. It checks Rekor entries. It checks certificate subjects. It checks fulcio CT logs. It checks identity claims the upstream git verify-commit cannot check.

PoC: GHSA-7rmh-48mx-2vwc. The end-to-end reproducer landed in the fix commit as internal/gitsign/invalid_object_test.go.

Gitsign verify exists to do more checking than git verify-commit does. For three years, the additional checking ran over bytes git-core could not see.