From dc60dfc4908584fd7903f54b754c1ce0b3e82d2c Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Wed, 11 Nov 2026 07:51:31 -0600 Subject: [PATCH] fix(id): sign_footer refuses unsupported version and duplicate roster (#6843) --- pkgs/id/src/match_audit.rs | 45 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/pkgs/id/src/match_audit.rs b/pkgs/id/src/match_audit.rs index df6aa328e6..a5a6098fbc 100644 --- a/pkgs/id/src/match_audit.rs +++ b/pkgs/id/src/match_audit.rs @@ -475,8 +475,10 @@ fn hash_parts(parts: &[&[u8]]) -> Hash { /// /// # Errors /// -/// Returns [`AuditErrorV0::SignerNotInRoster`] when the caller's key is -/// absent from `header.players`, and +/// Returns [`AuditErrorV0::UnsupportedVersion`] for a header version this +/// implementation does not understand, [`AuditErrorV0::Roster`] for an +/// empty or duplicate-key roster, [`AuditErrorV0::SignerNotInRoster`] when +/// the caller's key is absent from `header.players`, and /// [`AuditErrorV0::SeedCommitmentMismatch`] when the digest of /// `footer.seed_reveal` differs from `header.seed_commitment` — the /// footer-local rules [`MatchLogV0::verify_integrity`] applies, checked @@ -488,6 +490,10 @@ pub fn sign_footer( metadata: &MetadataV0, footer: &FooterV0, ) -> Result { + if header.version != FORMAT_VERSION_V0 { + return Err(AuditErrorV0::UnsupportedVersion(header.version)); + } + validate_roster(&header.players)?; validate_signer(key, header)?; if Hash::digest(&footer.seed_reveal) != header.seed_commitment { return Err(AuditErrorV0::SeedCommitmentMismatch); @@ -1146,6 +1152,41 @@ mod tests { assert!(matches!(error, AuditErrorV0::SignerNotInRoster)); } + #[test] + fn sign_footer_refuses_unsupported_version() { + let log = fixture(); + let mut header = log.header.clone(); + header.version = FORMAT_VERSION_V0 + 1; + let error = sign_footer( + &key(1), + &header, + log.entries[1].hash, + &log.metadata, + &log.footer, + ) + .unwrap_err(); + assert!( + matches!(error, AuditErrorV0::UnsupportedVersion(version) if version == FORMAT_VERSION_V0 + 1) + ); + } + + #[test] + fn sign_footer_refuses_duplicate_roster() { + let log = fixture(); + let mut header = log.header.clone(); + let duplicate = header.players[0].clone(); + header.players.push(duplicate); + let error = sign_footer( + &key(1), + &header, + log.entries[1].hash, + &log.metadata, + &log.footer, + ) + .unwrap_err(); + assert!(matches!(error, AuditErrorV0::Roster)); + } + #[test] fn sign_footer_refuses_non_roster_signer() { let log = fixture();