T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/lineage.py:167
- Finding
- Live Ledger Verification Validates Only the Public Anchor Field<![CDATA[ ## Vulnerability Details **File Location**: `scripts/lineage.py:167-178` and `scripts/lineage.py:224-234` **Vulnerability Type**: Incomplete cryptographic chain validation **Risk Level**: High ### Vulnerable Code ```python # scripts/lineage.py:167-178 if os.path.exists(LEDGER_PATH): with open(LEDGER_PATH) as f: lines = [l.strip() for l in f if l.strip()] if lines: first = json.loads(lines[0]) if first.get("previous_hash") != MOSES_ANCHOR: print("[LINEAGE FAIL] Ledger genesis does not trace to origin anchor.") print(" Chain custody broken — this is not a sovereign implementation.") sys.exit(1) print(f"[LINEAGE OK] Layer 0: anchor traces to origin-cycle filing.") ``` The machine-readable check uses the same incomplete validation: ```python # scripts/lineage.py:224-234 if os.path.exists(LEDGER_PATH): with open(LEDGER_PATH) as f: lines = [l.strip() for l in f if l.strip()] if lines: first = json.loads(lines[0]) if first.get("previous_hash") != MOSES_ANCHOR: sys.exit(1) print("LINEAGE:OK") sys.exit(0) ``` ### Technical Analysis Both verification paths inspect only the first ledger entry's `previous_hash`. Because `MOSES_ANCHOR` is publicly computable from constants embedded in the source, possession of this value provides no authentication. The implementation does not: - Recompute the first entry's hash from its canonical contents. - Compare the recomputed genesis hash with `record["genesis_hash"]`. - Validate that the first entry is a legitimate genesis event. - Recompute hashes for subsequent ledger entries. - Verify that each subsequent `previous_hash` equals the preceding entry's hash. - Reject an absent or empty ledger. - Detect modification, deletion, reordering, or insertion of later entries. Consequently, this is an anchor-field equality check rather than full ledger-chain verification. It contradicts the documented claim that ...[truncated 1146 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Define and enforce a strict schema for genesis and ordinary ledger entries. - Require a nonempty ledger when live-ledger verification is claimed. - Remove each entry's stored `hash`, canonicalize all remaining fields, and recompute SHA-256. - Compare every recomputed hash with the stored hash. - Require the genesis entry's `previous_hash` to equal `MOSES_ANCHOR`. - Require the recomputed genesis hash to equal `record["genesis_hash"]`. - For every later entry, require `entry["previous_hash"]` to equal the verified hash of the preceding entry. - Reject malformed JSON, duplicate sequence numbers, missing fields, reordered entries, and trailing invalid data. - Make `cmd_check` call the same full verification routine as `cmd_verify` so the two commands cannot diverge. - If authenticity against local file replacement is required, authenticate a trusted chain head using a protected signing key or an external transparency log. ]]>
