T09 · Insecure Skill Coding Practices
- Location
scripts/evidence_chain_check.py:11- Finding
Evidence integrity validation can be bypassed with incomplete or self-consistent metadata
- Content
View full analysis
Vulnerability Details
File Location:
scripts/evidence_chain_check.py, lines 11–27
Vulnerability Type: Insufficient cryptographic and schema validation
Risk Level: HighVulnerable Code
python for i, e in enumerate(chain): subj = e.get("subject") if subj: subjects.add(subj) t = e.get("time") if last_t is not None and t is not None and t < last_t: breaks.append("时间倒序 @" + str(i)) last_t = t h = e.get("hash") if prev_hash is not None and e.get("prev") != prev_hash: breaks.append("哈希链断裂 @" + str(i)) prev_hash = h if len(subjects) > 1: breaks.append("主体不一致:" + "/".join(sorted(subjects))) return {"breaks": breaks, "complete": len(breaks) == 0, "subjects": sorted(subjects)}Technical Analysis
The checker trusts integrity metadata supplied inside the evidence JSON. It only compares each record's
prevvalue with the preceding record's declaredhash; it never cryptographically recomputes a record digest from the evidence content.Mandatory fields are also not enforced:
- A missing
subjectis silently ignored. - Missing timestamps do not cause rejection.
- Missing hashes can prevent link validation because the comparison runs only when
prev_hash is not None. - An empty chain produces no break conditions and is therefore reported as complete.
- Arbitrary modified records pass when their attacker-supplied
hashandprevvalues remain mutually consistent.
Consequently, structural consistency of untrusted metadata is treated as proof of evidence integrity. This crosses the trust boundary between an untrusted evidence source and the compliance decision consumed by an auditor or automated gate.
Attack Path
- An attacker supplies or modifies an evidence-chain JSON value before it is checked.
- The attacker removes integrity fields or changes evidence content.
- The attacker either omits
hashandprevvalues or assigns arbitrary values that remain internally consistent ...[truncated 984 chars]
- A missing
- Remediation
View remediation
Remediation Suggestions
- Define and enforce a strict schema for every evidence record.
- Reject empty chains and records missing required fields such as
id,time,subject,hash, andprev. - Validate field types and accepted timestamp formats before comparing values.
- Define a deterministic canonical serialization for the fields protected by each hash.
- Cryptographically recompute every record's digest from its canonical content and compare it with the declared
hash. - Verify each
prevvalue against the independently recomputed digest of the preceding record. - Define and validate an explicit genesis-link rule for the first record.
- Restrict hashing to approved algorithms and include an algorithm identifier in the validated schema.
- If authenticity is claimed, verify digital signatures against explicitly trusted keys rather than trusting signature fields in the input.
- Add negative tests for empty arrays, missing fields, altered content with unchanged hashes, fabricated self-consistent links, mixed subjects, invalid timestamps, and malformed record types.
