Skip to content

fix(signature): reject non-object claims and trailing-newline producer ids (#157) - #162

Merged
rajnisht7 merged 2 commits into
agentrust-io:mainfrom
drk-ram:drk-ram-fix-signature-157
Nov 29, 2026
Merged

rajnisht7 merged 2 commits into
agentrust-io:mainfrom
drk-ram:drk-ram-fix-signature-157

Conversation

@drk-ram

@drk-ram drk-ram commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Closes #157. #157 lists four gaps in src/trace_verify/_signature.py. Against merge base 06f0485, 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)

Already on main, now pinned by tests (no behaviour change)

Not in this diff. The earlier summary also described detached-envelope and embedded-claim checks (producer and signature typing, cnf handling, and binding cnf.jwk.x to a registered producer's key). This PR contains no such change, so none of that is claimed here.

Registry impact

  • This PR does not modify any existing line under registry/

No file under registry/ or producers/ changes.

Checks

  • pytest passes
    • python -m pytest tests/test_signature.py tests/test_trace_verify_pkg.py -q --tb=short (with PYTHONPATH=src) -> 83 passed, 51 subtests passed.
    • python -m pytest -q --tb=short (with PYTHONPATH=src) -> 441 passed, 958 subtests passed, 1 failed. The failure is tests/test_release_safeguards.py::TestInstalledArtifactChecks::test_actual_chain_controls, which also fails on 06f0485 on Windows (it asserts a /altered.ndjson path suffix); it does not touch this change.
    • ruff check . -> all checks passed; git diff --check -> clean.
  • Registry and producer files still validate (tools/validate_registry.py -> OK, 3 day files; tools/validate_producers.py -> OK, 3 producer key files)
  • If the anchor format or verification semantics changed, docs/anchor-format.md is 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.
  • Commits are signed off (DCO)

@drk-ram
drk-ram requested review from a team, lywinged and rajnisht7 as code owners October 25, 2026 05:46
@drk-ram
drk-ram force-pushed the drk-ram-fix-signature-157 branch from 7c2b370 to 4661e8b Compare October 29, 2026 17:14
@drk-ram
drk-ram force-pushed the drk-ram-fix-signature-157 branch 2 times, most recently from ecb5184 to 896dd75 Compare November 15, 2026 18:21

@noah-ing noah-ing left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@drk-ram
drk-ram force-pushed the drk-ram-fix-signature-157 branch from 896dd75 to 8393cfe Compare November 22, 2026 16:14
@drk-ram drk-ram changed the title fix(signature): enforce strict JSON/profile and producer key binding across envelopes and claims (#157) fix(signature): reject non-object claims and trailing-newline producer ids (#157) Nov 22, 2026
@drk-ram

drk-ram commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

@noah-ing agreed on both points, updated in 8393cfe.

  • verify_claim_signature no longer carries its own JWK checks. The non-object and private/symmetric rules live only in validate_public_key_jwk, so the field-naming diagnostic is back. I also dropped the private-parameter loop from the new pad-bit test since TestJwkHardeningAndValidateProducers already covers it.
  • Added test_non_object_claim_raises_value_error: a non-object claim raises ValueError("claim must be a JSON object") and fails with AttributeError against 06f0485. I also pinned the non-object JWK case through verify_claim_signature so the shared helper's behaviour is covered after the removal.
  • Rewrote the description against 06f0485 using the repo template, and squashed to one commit with a matching message and title. Only the trailing-newline producer id, the non-object claim, and an early len % 4 == 1 base64url rejection are new; canonical round-tripping, strict key loading, non-finite constants and the JWK rules are marked as already on main with the tests that pin them. The detached-envelope and embedded-claim binding is called out as not part of this diff.
  • Re-ran: 83 passed on the signature/package tests, ruff check and git diff --check clean, validators OK. The full suite has one Windows-only failure (test_actual_chain_controls) that fails identically on 06f0485.

@noah-ing noah-ing left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 rajnisht7 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 noah-ing left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@drk-ram
drk-ram force-pushed the drk-ram-fix-signature-157 branch from 8393cfe to da27fd2 Compare November 28, 2026 22:56
@drk-ram

drk-ram commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

@rajnisht7 @noah-ing Fixed and force-pushed after rebasing onto current main.

What changed:

Validation run:

  • pytest -q tests/test_signature.py --cov=trace_verify._signature --cov-report=term-missing (32 passed)
  • ruff check . (passed)

@noah-ing noah-ing left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@rajnisht7
rajnisht7 merged commit fdd2558 into agentrust-io:main Nov 29, 2026
7 of 9 checks passed
@drk-ram

drk-ram commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Thank you @rajnisht7 and @noah-ing for the careful review on the schema/runtime producer-ID newline handling and for merging this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(trace_verify/_signature): enforce canonical base64url, reject private JWK members, and use strict JSON in load_producer_key

3 participants