fix(x402): treat expires_at == 0 as the "no expiry" sentinel#95
Open
kite-builds wants to merge 1 commit into
Open
fix(x402): treat expires_at == 0 as the "no expiry" sentinel#95kite-builds wants to merge 1 commit into
kite-builds wants to merge 1 commit into
Conversation
PaymentOffer.is_expired() only special-cased None, so an offer with expires_at == 0 evaluated `time.time() > 0` and always reported expired — X402Middleware._validate_offer then rejected it with "Payment offer expired". But 0 is the project's own documented "no expiry" sentinel on the ZAP wire format: zap_transport.py encodes `offer.expires_at or 0` and decodes back with `int(expires) if expires else None`, and the schema comment states `# 0 sentinel = "no expiry"`. So a never-expiring offer round-tripped through the binary path (None -> 0) and then evaluated on the JSON/header path was wrongly treated as expired — a cross-transport inconsistency. Fix: treat a falsy expires_at (None or 0) as "never expires" in is_expired(), aligning the JSON/header path with the ZAP binary path. Behaviour for None and for positive timestamps is unchanged. Adds two regression tests (the unit case + the _validate_offer end-to-end case). Full suite: 173 passed, 56 skipped.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
PaymentOffer.is_expired()only special-casedNone:So an offer with
expires_at == 0evaluatestime.time() > 0, which is alwaysTrue→ the offer reports itself expired, andX402Middleware._validate_offer()rejects it withPayment offer expired at 0.Why 0 should mean "no expiry"
0is the project's own documented "no expiry" sentinel on the ZAP wire format. Fromswitchboard/zap_transport.py:.uint64("expires_at") # 0 sentinel = "no expiry"ob.set_uint64(f["expires_at"], offer.expires_at or 0)(None→0)expires_at=int(expires) if expires else None(0→None)So a never-expiring offer that round-trips through the binary path (
None→0) — or any 402 server that sends{"expiresAt": 0}to mean "never expires" — is then wrongly treated as expired on the JSON/header path. The two transports disagree.Reproduce
Fix
Treat a falsy
expires_at(Noneor0) as "never expires", aligning the JSON/header path with the ZAP binary path. Behaviour forNoneand for positive timestamps is unchanged.Tests
Adds two regression tests (the unit case + the
_validate_offerend-to-end case). Full suite: 173 passed, 56 skipped.🤖 Generated with Claude Code