caelum0x 1fa477b0df fix(near-x402): close transaction-hash payment replay across resources
Adversarial testing found a real, confirmed critical bug: the NEAR x402
self-verified facilitator only deduped payment proofs by sha256 of the
client-supplied PAYMENT-SIGNATURE header bytes, not by the real on-chain
transaction they decode to. Since a NEAR transfer is public ledger data,
anyone who observes ONE valid (signerId, transaction) pair for a payment
to the configured payTo account could re-encode it inside a byte-different
header (reordered JSON keys / an added ignored field) to mint a brand-new
paymentProofHash that the existing replay() barrier had never seen, and
ride that single real payment to an unlimited number of free paid
credit-score requests for unrelated agent_ids. Reproduced live against
the real store/gateway/finality code with a mocked RPC returning one
confirmed transaction: 3 distinct free settlements from 1 payment before
the fix, correctly reduced to 1 settlement + 2 rejections after it.

Fixes it with a second, independent, durably-atomic claim index keyed on
the transaction hash itself (NearPaymentAttemptStore.claimTransaction,
first-claim-wins via an exclusive `wx` file create, same primitive the
existing paymentProofHash claim uses), checked right after authorize()
and before the costly settle() RPC call. A legitimate retry of the SAME
resource with a re-encoded header still gets served the cached settled
response; a different resource request reusing someone else's already-
consumed transaction is rejected with 409.

Algorand/QIE x402 paths were checked for the same pattern and are not
affected: both settle through a real third-party x402 facilitator
(@x402/avm, @x402/evm) against a single-use signed-but-unbroadcast
payload, not a self-verified reference to an already-public transaction
— this exact replay primitive is unique to NEAR's hand-rolled facilitator
(no @x402/near package exists).

14/14 existing NEAR x402 tests still green, typecheck clean.
2026-11-07 01:31:31 +03:00
..
2026-06-16 02:50:52 +03:00
2026-06-16 02:50:52 +03:00