Repository navigation
fix(signature): reject non-object claims and trailing-newline producer ids (#157) - #162
Conversation
7c2b370 to
4661e8b
Compare
ecb5184 to
896dd75
Compare
noah-ing
left a comment
There was a problem hiding this comment.
Reviewed 896dd753c55e8c7bfe698a8fd1a8988be52ffd84 against merge base 06f0485 and issue #157. The 27 signature tests and 54 packaged verifier tests passed locally, as did Ruff and git diff --check. The hosted validation and fuzz jobs passed.
Please simplify the JWK checks and pin the new claim-object contract. validate_public_key_jwk already rejects a non-object JWK and detects private or symmetric parameters. The added checks in verify_claim_signature duplicate those rules and replace the existing diagnostic that identifies the rejected fields. Keep validation in the shared helper, and add a direct test that a non-object claim raises the documented ValueError. The new producer-ID test covers the stricter match.
Please also refresh the PR description against this merge base. Canonical base64url round-tripping, strict producer-key file loading, and rejection of named non-finite JSON constants already exist there. The diff does not add the detached-envelope or embedded-claim binding paths named in the summary. Distinguishing the new guards from existing coverage will make it clear which parts of #157 this PR closes.
896dd75 to
8393cfe
Compare
|
@noah-ing agreed on both points, updated in 8393cfe.
|
noah-ing
left a comment
There was a problem hiding this comment.
Re-reviewed exact head 8393cfed78c5ea8c0a9fd0dc0432eff1ebeb042d against my prior changes request. The duplicated JWK checks are gone from verify_claim_signature; the shared validator again owns the non-object and private/symmetric-key diagnostics. The new direct claim-object test asserts the documented ValueError, and the PR description now separates the new guards from behavior already on main.
All 29 signature tests and 35 subtests passed locally. The current-head validation, changed-code fuzz, and CodeQL checks pass. I found no remaining issue in the changed signature path and approve this scope.
rajnisht7
left a comment
There was a problem hiding this comment.
One thing remains: Schema / runtime mismatch-Both schema/producer-key.schema.json and schema/registry-entry.schema.json still end the producer-id pattern with $. Runtime now uses \Z + fullmatch, so "cmcp-gateway/0.1.0\n" is rejected by is_valid_producer_id / load_producer_key but still accepted by both schemas, verified end-to-end: a producer key with a trailing-newline producer_id (and matching filename) passes tools/validate_producers.py (exit 0) but is refused by the runtime loader. Kindly update both schema patterns so they reject a trailing newline, and add regression tests that cover schema validation + parity with is_valid_producer_id.
Non-blocking: no direct test for the new len(value) % 4 == 1 branch, existing cases don’t hit a pure length-≡1 string of valid base64url alphabet
Also kindly resolve conflicts and rebase onto main
noah-ing
left a comment
There was a problem hiding this comment.
Re-reviewed exact head 8393cfed78c5ea8c0a9fd0dc0432eff1ebeb042d after Rajnish's schema/runtime finding. My November 24 approval covered the corrected signature path, but it cannot stand as an approval of this head with the producer-ID mismatch.
Both schema/producer-key.schema.json and schema/registry-entry.schema.json end the producer-ID pattern with $. Their patterns match cmcp-gateway/0.1.0\n, while the runtime's is_valid_producer_id() rejects it with fullmatch(). I independently checked both patterns and the runtime predicate; the schema-based producer validator can therefore accept a key file that the runtime loader will not use, as Rajnish reported. Please align both schemas with the runtime rule and add a schema/validator/loader parity regression for the trailing-newline ID. The branch also currently conflicts with main and needs reconciliation before a fresh review. This does not change my earlier assessment of the JWK and claim-object fixes.
…r ids (agentrust-io#157) verify_claim_signature raised AttributeError on a claim that is not a JSON object; it now raises ValueError("claim must be a JSON object"). JWK shape and private or symmetric parameter checks stay in validate_public_key_jwk so its field-identifying diagnostic is preserved. is_valid_producer_id used a pattern anchored with $ and re.match, which accepts a trailing newline; it now uses fullmatch with \Z. The base64url pattern gets the same anchor, and a length that no base64 input can have is refused before decoding. Canonical base64url round-tripping, strict JSON in load_producer_key and non-finite constant rejection already exist on main; tests pin them for the signature and key inputs, and the loads_unique docstring now names the non-finite refusal it already performs. Signed-off-by: Raghuvar Karthik Durga <177662415+drk-ram@users.noreply.github.com>
Update producer regex patterns so Draft 2020-12 validation rejects newline-terminated IDs under both ECMA-262 and Python jsonschema behavior. Add regression coverage for schema/runtime parity, validate_producers enforcement, and the base64url len%4==1 rejection branch. Signed-off-by: Raghuvar Karthik Durga <177662415+drk-ram@users.noreply.github.com>
8393cfe to
da27fd2
Compare
|
@rajnisht7 @noah-ing Fixed and force-pushed after rebasing onto current What changed:
Validation run:
|
noah-ing
left a comment
There was a problem hiding this comment.
Re-reviewed exact head da27fd2cefb9d69a04cb5f51fe5fd66ba9d44e79 against current main 119d243 and my November 27 request. Both producer-ID schemas now reject trailing LF/CR (including CRLF) under Python JSON Schema and ECMA-262 regex behavior, while a valid ID remains accepted. The runtime predicate, key loader, and producer validator reject the newline case too. The new test directly reaches the base64url length-≡1 branch; the earlier JWK and claim-object fixes remain intact. The branch merges cleanly. Focused signature/package tests finished with 85 passed, 1 skipped, and 51 subtests; Ruff, diff checks, and current-head hosted validation, fuzz, and analysis pass. I found no blocking defect in this changed scope and approve.
Please refresh the PR description before merge: it still names merge base 06f0485, lists prior-head test counts, and omits the two schema edits. This review establishes newline parity, not complete producer-ID parity; a separate pre-existing double-dot ID mismatch remains outside this patch.
|
Thank you @rajnisht7 and @noah-ing for the careful review on the schema/runtime producer-ID newline handling and for merging this. |
What and why
Closes #157. #157 lists four gaps in
src/trace_verify/_signature.py. Against merge base06f0485, items 1 and 3 and the JWK half of item 2 are already fixed on main. This PR closes the rest (item 4 and the claim half of item 2) and adds regression tests for the parts that were already fixed.New in this diff (behaviour change)
is_valid_producer_idmatches withfullmatchand an\Zanchor, so"cmcp-gateway/0.1.0\n"is no longer a valid producer id (fix(trace_verify/_signature): enforce canonical base64url, reject private JWK members, and use strict JSON in load_producer_key #157 item 4). Covered by the added assertion inTestLoadProducerKey.test_accepts_valid_producer_id.verify_claim_signatureraisesValueError("claim must be a JSON object")for a claim that is not a JSON object, where it raisedAttributeErrorfromclaim.get(the claim half of fix(trace_verify/_signature): enforce canonical base64url, reject private JWK members, and use strict JSON in load_producer_key #157 item 2). Covered byTestVerifyClaimSignature.test_non_object_claim_raises_value_error._BASE64URL_REgets the same\Zanchor, and_decode_base64urlrefuses a length no base64 input can have (len % 4 == 1) before decoding. The verdict is unchanged; the error now saysis not unpadded base64urlinstead of surfacing the decoder's message.loads_uniquenow names the non-finite constant refusal it already performs.Already on main, now pinned by tests (no behaviour change)
_decode_base64url(fix(trace_verify/_signature): enforce canonical base64url, reject private JWK members, and use strict JSON in load_producer_key #157 item 1):test_rejects_noncanonical_pad_bits_in_signature_and_public_keyadds the signature alias, which had no test; thexalias was already covered bytest_rejects_noncanonical_base64url_x.verify_claim_signaturekeeps no separate checks and callsvalidate_public_key_jwk, which names the rejected fields.TestJwkHardeningAndValidateProducersalready covers the parameters;test_non_object_jwk_raises_value_error_from_the_shared_validatorpins the non-object case throughverify_claim_signature.load_producer_key(fix(trace_verify/_signature): enforce canonical base64url, reject private JWK members, and use strict JSON in load_producer_key #157 item 3):test_load_producer_key_rejects_duplicate_keys_nonfinite_and_non_dict.Not in this diff. The earlier summary also described detached-envelope and embedded-claim checks (
producerandsignaturetyping,cnfhandling, and bindingcnf.jwk.xto a registered producer's key). This PR contains no such change, so none of that is claimed here.Registry impact
registry/No file under
registry/orproducers/changes.Checks
pytestpassespython -m pytest tests/test_signature.py tests/test_trace_verify_pkg.py -q --tb=short(withPYTHONPATH=src) -> 83 passed, 51 subtests passed.python -m pytest -q --tb=short(withPYTHONPATH=src) -> 441 passed, 958 subtests passed, 1 failed. The failure istests/test_release_safeguards.py::TestInstalledArtifactChecks::test_actual_chain_controls, which also fails on06f0485on Windows (it asserts a/altered.ndjsonpath suffix); it does not touch this change.ruff check .-> all checks passed;git diff --check-> clean.tools/validate_registry.py-> OK, 3 day files;tools/validate_producers.py-> OK, 3 producer key files)docs/anchor-format.mdis updated in the same PR, and existing inclusion proofs still verify. Not applicable: the anchor format and inclusion proofs are unchanged; a valid claim and key verify exactly as before.