Skip to content

fix(capture-core): reject duplicate JSON keys and non-finite numbers in load_state/sha_mapping and check seal.alg in check_seal #366

Open

Description

@drk-ram

Summary

Three state-integrity boundary gaps exist in packages/agentrust-capture-core/src/agentrust_capture_core/:

  1. Duplicate JSON keys and non-finite constants accepted in load_state (packages/agentrust-capture-core/src/agentrust_capture_core/state.py lines 65-80):

    • load_state(path) calls bare json.loads(path.read_text(encoding="utf-8")) without object_pairs_hook or parse_constant, accepting state/baseline files with duplicate JSON keys or NaN/Infinity constants instead of returning None (corrupt state).
  2. allow_nan=True default in sha_mapping (packages/agentrust-capture-core/src/agentrust_capture_core/hashing.py lines 76-80):

    • sha_mapping(value) calls json.dumps(value, sort_keys=True, separators=(",", ":")) without allow_nan=False, allowing NaN and Infinity to serialize into non-standard JSON before hashing.
  3. Unchecked seal["alg"] in check_seal (packages/agentrust-capture-core/src/agentrust_capture_core/seal.py lines 61-71):

    • attach_seal writes {"alg": "SHA-256", "digest": state_digest(snapshot), "sealed_at": ...}, but check_seal only checks isinstance(seal.get("digest"), str) and seal["digest"] == state_digest(snapshot), returning INTEGRITY_OK even when seal.get("alg") != "SHA-256".

Proposed Fix

  • Reject duplicate JSON keys and NaN/Infinity constants in load_state (returning None).
  • Pass allow_nan=False to json.dumps in sha_mapping.
  • Check seal.get("alg") == "SHA-256" in check_seal, returning INTEGRITY_BROKEN when "alg" is present and not "SHA-256".

Activity

  1. github-actions commented on Oct 23, 2026

    @github-actions
    Contributor

    🟡 Contributor Check: MEDIUM

    Check Result
    Profile MEDIUM
    Credential LOW
    Overall MEDIUM

    Automated check by AgenTrust Contributor Check.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions