-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## Gitsign verified a re-encoding\n\nThe 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:\n\n```go\nc, err := repo.CommitObject(*h)\nif err != nil {\n return fmt.Errorf(\"error reading commit object: %w\", err)\n}\n\nsig := []byte(c.PGPSignature)\np, _ := pem.Decode(sig)\nif p == nil || p.Type != \"SIGNED MESSAGE\" {\n return fmt.Errorf(\"unsupported signature type\")\n}\n\nc2 := new(plumbing.MemoryObject)\nif err := c.EncodeWithoutSignature(c2); err != nil {\n return err\n}\nr, err := c2.Reader()\n// ...\ndata, err := io.ReadAll(r)\n// ...\nsummary, err := v.Verify(ctx, data, sig, true)\n```\n\nThe 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`.\n\nWhen 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.\n\nGitsign 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.\n\n## go-git is last-wins. git-core is first-wins.\n\nA 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.\n\nBoth implementations accept the input. Both consider the second header a no-op for the structure they build. They simply build opposite structures.\n\nFor 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.\n\nGitsign'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.\n\n## What the forgery looks like\n\nThe 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:\n\n```go\nconst (\n legitTree = \"b333504b8cf3d9c314fed2cc242c5c38e89534a5\"\n attackerTree = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n author = \"author Alice 1700000000 +0000\"\n committer = \"committer Alice 1700000000 +0000\"\n message = \"legit commit\\n\"\n)\n\n// Canonical commit body, what Alice intended to sign. One tree header,\n// message \"legit commit\".\ncanonical := []byte(fmt.Sprintf(\"tree %s\\n%s\\n%s\\n\\n%s\",\n legitTree, author, committer, message))\n\nresp, err := signature.Sign(ctx, id, canonical, signature.SignOptions{\n Detached: true,\n Armor: true,\n IncludeCerts: 0,\n})\n```\n\nAlice signs `tree \\nauthor ...\\ncommitter ...\\n\\nlegit commit\\n`. The signature attests to those bytes. Nothing about the signing operation is unusual.\n\nThe attacker assembles a commit Alice did not write:\n\n```go\nmalformedRaw := []byte(fmt.Sprintf(\n \"tree %s\\ntree %s\\n%s\\n%s\\n%s\\n%s\",\n attackerTree, legitTree,\n author, committer,\n indent(\"gpgsig \", string(resp.Signature)),\n message,\n))\n```\n\nTwo `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.\n\n`gitsign verify ` 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.\n\n`git verify-commit ` 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.\n\nA 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.\n\n## The signature was over bytes nobody else uses\n\nThe regression test asserts both halves of the disagreement in code:\n\n```go\nt.Run(\"signature is a genuine forgery against the re-encoded form\", func(t *testing.T) {\n reencoded := reencodeViaGoGit(t, malformedRaw)\n if _, err := gv.Verify(ctx, reencoded, resp.Signature, true); err != nil {\n t.Fatalf(\"expected signature to verify over re-encoded bytes: %v\", err)\n }\n})\n\nt.Run(\"fix: signature fails to verify against the raw malformed bytes\", func(t *testing.T) {\n c, err := git.SplitCommit(bytes.NewReader(malformedRaw))\n if err != nil { t.Fatalf(\"SplitCommit: %v\", err) }\n if _, err := gv.Verify(ctx, c.Payload, c.Gpgsig, true); err == nil {\n t.Fatalf(\"expected signature verification to fail against malformed raw bytes\")\n }\n})\n```\n\nThe 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.\n\nThe 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.\n\nThe 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.\n\n## The patch admits the design\n\nThe 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:\n\n```go\n// SplitCommit parses the raw bytes of a commit object (object-database form,\n// without the \"commit \\0\" prefix) into payload + signatures.\n//\n// It operates purely on the raw bytes, mirroring what git-core feeds to its\n// signature verifier, and does not go through go-git's object parser.\n//\n// The trust-confusion class of attack (GHSA-7rmh-48mx-2vwc) relied on gitsign\n// re-encoding through go-git before verification, which normalized away\n// duplicate headers and let a signature over the canonical form verify\n// against attacker-controlled raw bytes. Verifying directly over the raw\n// bytes blocks that: any structural divergence between what was signed and\n// what's stored makes the signature fail to verify cryptographically.\n// Consequently, SplitCommit doesn't reject merely \"weird but git-valid\"\n// objects (e.g. duplicate tree headers); the signature check below is what\n// catches them.\n```\n\nThe 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.\n\nThis 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:\n\n> 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.\n\nThe 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.\n\n## The parser was not the only one\n\nThe companion fix landed nine days later as commit `03848e9` on May 15, 2026, titled \"Reject malformed objects in attest predicate generation.\" Its commit message:\n\n> 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.\n\ngo-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.\n\nEvery 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.\n\n## Canonicalize before verify\n\nThe 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.\n\nPR #262, the one that added `gitsign verify` in March 2023, opened with this rationale:\n\n> 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.\n\n`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.\n\nPoC: [GHSA-7rmh-48mx-2vwc](https://github.com/sigstore/gitsign/security/advisories/GHSA-7rmh-48mx-2vwc). The end-to-end reproducer landed in the fix commit as [internal/gitsign/invalid_object_test.go](https://github.com/sigstore/gitsign/blob/main/internal/gitsign/invalid_object_test.go).","closing_line":"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.","hook_md":"`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.","post_id":444,"slug":"gitsign-cve-2026-44309-verified-the-re-encoding","title":"CVE-2026-44309: Gitsign Verified a Re-encoding. The Re-encoding Was Not the Object Git-core Ships.","type":"initial","unreadable_sentence":"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."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCawJOzgAKCRDeZjl4jgkQ Jp8FAP4kRg/jQuFLBC7wU6+JInQoT0ipN6Vp1e+JB9ESwGox9AD/UN+k90LqXD8t l3tDGIZomcI8BIznCee05EISL+qsUwY= =eDpo -----END PGP SIGNATURE-----