caelum0x d9c41cf082 fix(turnstile): settlement-admission idempotency check wasn't constant-time
begin_verification (both InMemorySettlementJournal and
PostgresSettlementJournal — the latter is what's actually live) decides
whether a resubmitted nonce is an idempotent retry of the same
PaymentAuthorization, or a different command colliding on that nonce, by
comparing the two with derived PartialEq (`==`/`!=` on every field,
including sig — the one field only the real payer's private key could have
produced). Same non-constant-time memcmp-shaped leak as the
settlement_for_payer bug fixed earlier today (aeaec8eb), just on the
payment-admission hot path every payment goes through instead of the
settlement-status lookup.

Fix: reuse the same approach — compare the full canonical JSON encoding of
both authorizations through a constant-time byte comparison
(authorization_matches, now shared from turnstile-core::journal so both the
in-memory and Postgres-backed journals use it). Added regression tests
pinning that idempotent exact retries still succeed and a same-nonce
near-miss (last byte of sig, first byte of sig) is still rejected.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-29 21:53:22 +03:00
..