Repository navigation
fix(examples): reject duplicate JSON keys, non-finite numbers, and boolean sequences in verify_receipts and verify_purchase (#369) - #373
Conversation
|
🟡 Contributor Check: MEDIUM
Automated check by AgenTrust Contributor Check. |
2638393 to
6e60236
Compare
carloshvp
left a comment
There was a problem hiding this comment.
Reviewed exact head 6e60236cdde1a907e7430049c263b32bc1b17f0b in an isolated checkout.
The example verifiers now reject ambiguous/non-finite JSON, boolean receipt sequence numbers, malformed purchase sections and non-integer/out-of-range minor-unit amounts while preserving the existing signed receipt and purchase fixtures. These checks establish the example's evidence/structure contract, not physical completion.
Validation: 9 receipt tests with 12 subtests and 8 purchase tests with 9 subtests passed. The repository's actual hosted Ruff subset (integrations/packages/scripts/tests/claude-code/copilot/plugins/scheduled-agents/shadow-ai; E4,E7,E9,F) and diff whitespace checks passed. An additional optional lint of the example tree reports two pre-existing E402 imports after its sys.path setup; that is outside the hosted subset and is not introduced here. Sign-offs are present. No blocking source finding; hosted CI and maintainer policy remain separate.
Reviewed with OpenAI Codex.
rajnisht7
left a comment
There was a problem hiding this comment.
the overall changes looks good, a few points needs to be addressed:
-
verify_purchase.digest()is still missingallow_nan=False. Receipts side got it, purchase side did not.digest({"x": float("nan")})currently succeeds and produces a hash. Programmatic path is not closed. -
The new duplicate-key test does not actually test duplicate keys. Fixture ends with
}\n, soraw[:-1] + ', "extra": 1, "extra": 2}'produces malformed JSON (extra data), not a duplicate-key object. It never hits_unique_object.
Also missing tests for the new purchase behaviors (safe-integer bound, section guards, parser-level NaN/duplicate rejection).
dinakarjs
left a comment
There was a problem hiding this comment.
Source follow-up at 6e60236. The diff leaves verify_purchase.digest using json.dumps without allow_nan=False, while receipt canonicalization now rejects non-finite values. Please cover both programmatic and parsed-input paths, as Rajnish requested.
For the duplicate-key regression, first establish that the crafted string is syntactically valid JSON under the ordinary decoder, then require the strict verifier to reject it. A guard-removal control should make that same fixture reach the accepting path; a generic malformed verdict alone does not establish that _unique_object ran. Keep the boolean-sequence case separate.
Add independent purchase cases for malformed sections and safe-integer boundaries, with valid boundary twins, plus parser duplicate/non-finite cases. I inspected the diff and existing review; I did not rerun tests or mutations in this pass. Reviewed with OpenAI Codex.
…olean sequences in verify_receipts and verify_purchase (agentrust-io#369) - Reject duplicate JSON object keys, NaN/Infinity constants, and float exponent overflow in examples/embodied-action-receipts/verify_receipts.py, pass allow_nan=False in canonical_bytes, and require integer receipt sequence numbers. - Guard non-dict sections, enforce safe-integer bounds on amount_minor and max_amount_minor, pass allow_nan=False in digest, and reject duplicate JSON keys, NaN/Infinity constants, and float exponent overflow in examples/agentic-commerce-accountability/verify_purchase.py. Closes agentrust-io#369 Signed-off-by: Raghuvar Karthik Durga <177662415+drk-ram@users.noreply.github.com>
6e60236 to
4e003dc
Compare
|
@rajnisht7 @dinakarjs @carloshvp Rebased onto
|
dinakarjs
left a comment
There was a problem hiding this comment.
Re-reviewed exact head 4e003dc on Linux/Python 3.12.14.
The purchase digest now refuses non-finite programmatic values; strict parsing covers duplicate members, constants and exponent overflow. The receipt duplicate-key fixture is valid under the ordinary decoder and reaches the accepting document verifier before strict parsing refuses it, so the negative no longer relies on malformed syntax. Boolean sequence, purchase section shape and safe-integer boundary controls are separate. Fresh receipt hash-lock environment: 11 receipt unittest methods and 12 purchase unittest methods pass; whitespace passes. My earlier follow-up is addressed within these offline examples. No live-commerce, real-controller or production authorization assurance is claimed.
Reviewed with OpenAI Codex.
carloshvp
left a comment
There was a problem hiding this comment.
Reviewed current head 4e003dc4da085467e82cc13b55d5a3ab59a6fcd9 in an isolated checkout.
Both fixture loaders reject duplicate JSON members, literal non-finite values and exponent overflow. Programmatic digest/canonical serialization refuses non-finite values; boolean receipt sequences are refused. The valid signed fixture remains accepted, while its duplicate-key twin is rejected before verification. Both example suites pass (12 commerce and 11 embodied cases), plus all 60 root tests.
The repository CI Ruff selection and whitespace checks pass; all PR commits carry DCO sign-offs. This approves the bounded software scope. Current-head hosted checks and maintainer requirements remain applicable.
Reviewed with OpenAI Codex.
Summary
NaN/Infinityconstants, passallow_nan=False, and requiretype(receipt["sequence"]) is intinexamples/embodied-action-receipts/verify_receipts.py.<= 2**53 - 1) onamount_minorandmax_amount_minor, and reject duplicate JSON keys andNaN/Infinityinexamples/agentic-commerce-accountability/verify_purchase.py.Closes #369
Validation
python -m pytest examples/embodied-action-receipts/tests/test_verify_receipts.py examples/agentic-commerce-accountability/tests/test_verify_purchase.py -q