Skip to content

fix(security): anchor audit chain root in TEE attestation to prevent chain substitution (AUDIT-002) - #258

Merged
imran-siddique merged 3 commits into
mainfrom
fix/audit-002-chain-external-anchor
Jun 8, 2026
Merged

imran-siddique merged 3 commits into
mainfrom
fix/audit-002-chain-external-anchor

Conversation

@imran-siddique

Copy link
Copy Markdown
Member

Summary

  • Adds set_tee_anchor(chain_root) to AuditChain — records the chain root as an externally-committed value that verify_chain() checks in addition to internal hash links.
  • SessionManager.create_session() now derives a per-session nonce as SHA-256(chain_root_bytes || session_id_bytes), passes it to ctx.tee_provider.get_attestation_report() (committing the root into TEE evidence), then calls chain.set_tee_anchor(chain_root).
  • verify_chain() fails if the current chain_root no longer matches the anchored value — a replaced chain has a different root and cannot pass this check even if all internal hash links are valid. In dev / Level-0 mode (no anchor set), a warning is logged but verification does not fail.
  • TEE provider failure during session creation is non-fatal — logged as a warning, anchor is still set for in-process chain-substitution detection.

Closes #146.

Test plan

  • test_audit_chain_anchor.py (13 new tests):
    • test_set_tee_anchor_accepts_matching_chain_root — happy path anchor set
    • test_set_tee_anchor_rejects_mismatched_value — programming-error guard
    • test_verify_chain_warns_when_no_anchor — dev mode warning
    • test_verify_chain_fails_on_chain_substitution — attack path: graft replacement _entries, verify fails
    • test_create_session_sets_tee_anchor — anchor present after create_session
    • test_create_session_anchor_nonce_encodes_chain_root — nonce derivation verified
    • test_verify_chain_fails_after_chain_substitution_via_session_manager — end-to-end attack path
    • test_tee_provider_failure_still_sets_anchor — resilience path
  • test_session_manager.py — all 19 existing tests pass with tee_provider mock added to _make_ctx.

Generated with Claude Code

@imran-siddique
imran-siddique force-pushed the fix/audit-002-chain-external-anchor branch from e299610 to ce9741b Compare June 8, 2026 20:56
imran-siddique and others added 2 commits June 8, 2026 14:09
…chain substitution (AUDIT-002)

verify_chain() now checks the chain_root against an externally-committed
anchor value that is derived from a per-session TEE attestation nonce
(SHA-256 of chain_root_bytes || session_id_bytes).  An attacker who
discards _entries and constructs a fresh self-consistent chain will get a
different root that fails the anchor check even though all internal hash
links pass.  In dev / Level-0 mode (software-only TEE) verify_chain emits
a warning instead of failing.  Closes #146.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…loses #47) (#260)

29 tests organized into five classes — TestAudit001 through TestAudit005 —
covering monotonic timestamps, TEE anchor / chain substitution prevention,
canonical entry format with SHA-256 hashing, contiguous prev_entry_hash
chaining, and TRACE Claim sequence_number / prev_claim_hash linking.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
@imran-siddique
imran-siddique force-pushed the fix/audit-002-chain-external-anchor branch from ce9741b to 5cdcf1a Compare June 8, 2026 21:09
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@imran-siddique
imran-siddique merged commit 2312b54 into main Jun 8, 2026
8 checks passed
@imran-siddique
imran-siddique deleted the fix/audit-002-chain-external-anchor branch July 29, 2026 23:19
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.

HIGH: Audit chain verify_chain() has no external anchor — replaceable by a freshly constructed chain (AUDIT-002)

1 participant