Skip to content

fix: remove ambiguous encodings from hash inputs - #7492

Open
jmecom wants to merge 4 commits into
mainfrom
jm/fix-hash-input-encodings
Open

fix: remove ambiguous encodings from hash inputs#7492
jmecom wants to merge 4 commits into
mainfrom
jm/fix-hash-input-encodings

Conversation

@jmecom

@jmecom jmecom commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

problem

Buzz has several instances where the encoding of hash inputs is non-injective. This means that two semantically distinct inputs can produce the same hash. The core issue is lack of proper separation. For example, consider a protocol which hashes a first name and last name: hash("Jane"||"Doe") is equivalent to hash("Jan"||"eDoe"). Although the names are distinct, the input to the hash function is identical.

The correct approach is to, for example, use TLV-encoding or another unambiguous encoding. Each input is transformed:

First name: "Jane" -> {tag: "first", len: 4, value: "Jane"} -> "first::4::Jane"
Last name: "Doe" -> {tag: "last", len: 3, value: "Doe"} -> "last::3::Doe"

First name: "Jan" -> {tag: "first", len: 3, value: "Jan"} -> "first::3::Jan"
Last name: "eDoe" -> {tag: "last", len: 4, value: "eDoe"} -> "last::4::eDoe"

`hash("first::4::Jane"||"last::3::Doe") != hash("first::3::Jan"||"last::4::eDoe")`

fix

Replace ambiguous hash inputs in four places, with one fix per commit:

  • Audit rows use version 2 TLV encoding. Legacy verification checks cryptographic field widths and restricts object IDs to the UUID/hash forms used by existing producers.
  • Git signatures use version 2 with an attestation presence byte and field lengths. Legacy verification requires a commit or tag header, preventing two accepted interpretations of the same signed bytes.
  • OAuth cache identities use a versioned JSON tuple, preserving field and scope boundaries. Old caches are not imported because their configuration binding is ambiguous.
  • Deletion manifests reject embedded newlines at the digest helper, including the legacy v4 chunk-validation path. Valid v4/v5 digests stay unchanged.

Apply audit migration 0045 and upgrade audit/Git verifiers before deploying new writers. Existing audit hashes are retained; mixed-version chains verify. OAuth users must sign in once after upgrading. Legacy audit and Git checks cannot establish the original interpretation of arbitrary inputs hashed before the upgrade; the compatibility assumptions are documented.

Checked with the audit, Git signing, agent, and database suites (903 passed), including real Git commit/tag signing, OAuth integration tests, collision regressions, and PostgreSQL test discovery. Workspace formatting and Clippy pass.

Full repository checks are still running. Live PostgreSQL/Redis tests are blocked by Docker Desktop's organization sign-in requirement.

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

🔐 Codex Security Review

Status: review required for the current range.

The current range is 44316ff72f5f7de014c66b01cbf534298a70c249...dcd31486121528efa0c08e140c4878801e73ddd4.
A new review must complete for this exact range. When manual authorization
is required, a Block organization member must comment exactly
@buzz-security-review dcd31486121528efa0c08e140c4878801e73ddd4 to authorize a new review.
Any previous review applies only to its recorded range.

@jmecom jmecom changed the title fix: remove ambiguous encodings from security hashes fix: remove ambiguous encodings from hash inputs Sep 8, 2026
@jmecom
jmecom marked this pull request as ready for review September 8, 2026 19:27
@jmecom
jmecom requested a review from a team as a code owner September 8, 2026 19:27
Signed-off-by: Jordan Mecom <jm@squareup.com>
Signed-off-by: Jordan Mecom <jm@squareup.com>
Signed-off-by: Jordan Mecom <jm@squareup.com>
Signed-off-by: Jordan Mecom <jm@squareup.com>
@jmecom
jmecom force-pushed the jm/fix-hash-input-encodings branch from daa6f43 to dcd3148 Compare September 8, 2026 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant