Video in progress

Strong Middle 🌿 Git

Git names commits with SHA-1. After the SHAttered attack, is this a security problem, and where does the move to SHA-256 stand?

Since Git 2.13 it uses collision-detecting SHA-1 (SHA-1DC), which rejects SHAttered-style files. SHA-256 repos are created with --object-format=sha256, but support in hosting services and tools is still incomplete.

📖 Answer

In 2017 SHAttered produced two different PDFs with the same SHA-1 hash. For Git this is a theoretical risk: if someone prepared a "clean" and a "malicious" blob with the same hash, got you to accept the clean one, they could swap it later. A signed tag actually signs the commit hash, so the trustworthiness of the signature depends on the hash too.

What was done in practice:

  • since Git 2.13, SHA-1 computation runs with collision detection: if data characteristic of the attack shows up, the object is rejected. So the known attack does not work in Git;
  • the attack needs a specially prepared file and a lot of compute. For an ordinary team repo it is not the first risk: a stolen token or weak branch protection is far more real.

SHA-256:

git init --object-format=sha256 billing
git rev-parse --show-object-format   # sha1 or sha256

The problem is compatibility. There is still no direct push/fetch between SHA-1 and SHA-256 repos, an existing repo cannot be converted "in place", and many hosting and CI tools do not accept a SHA-256 repo yet or are in an experimental stage.

In an interview, this is what I say: on a project that is running today I stay with SHA-1, but I do not write scripts that depend on the short form of a hash (a1b2c3d), and I do not hard-code a 40-character hash, since in SHA-256 it is 64 characters.