Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/cmcp_runtime/policy/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,13 @@ def _revocation_object_pairs(pairs: list[tuple[str, Any]]) -> Any:
for key, value in pairs:
if key in out or value is _INVALID_REVOCATION_JSON:
return _INVALID_REVOCATION_JSON
if isinstance(value, list) and any(item is _INVALID_REVOCATION_JSON for item in value):
return _INVALID_REVOCATION_JSON
pending = [value]
while pending:
item = pending.pop()
if item is _INVALID_REVOCATION_JSON:
return _INVALID_REVOCATION_JSON
if isinstance(item, list):
pending.extend(item)
out[key] = value
return out

Expand Down
20 changes: 19 additions & 1 deletion tests/unit/test_policy_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,12 +445,15 @@ def test_bundle_and_approval_reject_non_canonical_base64url_and_duplicate_keys(b
load_policy_bundle(str(bundle_dir))


@pytest.mark.parametrize("extra", ('[[{"x":1,"x":2}]]', '[[NaN]]', '[[Infinity]]', '[[[[-Infinity]]]]'))
def test_revocation_file_rejects_duplicate_key_statement_without_blocking_valid_revocation(
bundle_dir,
bundle_dir, extra,
):
import base64

from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey

from cmcp_runtime.errors import PolicySigningKeyRevoked
from cmcp_runtime.policy.bundle import (
REVOCATION_FILE,
Expand Down Expand Up @@ -484,6 +487,21 @@ def test_revocation_file_rejects_duplicate_key_statement_without_blocking_valid_
assert keys1.apply_file(str(bundle_dir)) == []
assert keys1.current == cur_pub

# Even ignored extension data must be strict JSON at every array depth.
nested = (
f'[{{"revoked_key_id":"{cur_id}","signature":"{valid_sig}",'
f'"extra":{extra}}}]'
)
(bundle_dir / REVOCATION_FILE).write_text(nested, encoding="utf-8")
nested_keys = PolicySigningKeys(cur_pub, suc_pub)
assert nested_keys.apply_file(str(bundle_dir)) == []
assert nested_keys.current == cur_pub
# An invalid statement must not suppress the later valid statement.
valid = json.dumps({"revoked_key_id": cur_id, "signature": valid_sig})
(bundle_dir / REVOCATION_FILE).write_text(nested[:-1] + ',' + valid + ']', encoding="utf-8")
assert nested_keys.apply_file(str(bundle_dir)) == [cur_id]
assert nested_keys.current == suc_pub

# A malformed duplicate-key or NaN statement alongside a valid signed revocation
# must NOT block the valid revocation from revoking cur_pub.
mixed = (
Expand Down
Loading