T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/badge_issuer.py:30
- Finding
- Evidence Validation Can Be Bypassed to Issue Unsubstantiated Certificates## Vulnerability Details **File Location**: `scripts/badge_issuer.py`, lines 30-35 and 50-89 **Vulnerability Type**: Insufficient evidence validation and authorization gate bypass **Risk Level**: High ### Vulnerable Code ```python def load_evidence_ref(p: str) -> str: """证据引用:@文件/纯路径 → 内容哈希;否则按内联值哈希。""" q = p[1:] if p.startswith("@") else p if pathlib.Path(q).is_file(): return sha256_of(pathlib.Path(q).read_text(encoding="utf-8")) return sha256_of(p) ``` ```python # 三律门禁:每律至少 1 条证据 ev = {} laws_hit = set() for item in a.evidence: if "=" not in item: print(f"证据格式错误(应为 key=value):{item}", file=sys.stderr) sys.exit(2) k, v = item.split("=", 1) if not k.startswith(LAW_PREFIX): print(f"证据键须以 l1-/l2-/l3- 开头:{k}", file=sys.stderr) sys.exit(2) ev[k] = load_evidence_ref(v) laws_hit.add(k[:3]) missing = [l for l in ("l1-", "l2-", "l3-") if l not in laws_hit] reg_path = pathlib.Path(a.registry) reg = json.loads(reg_path.read_text(encoding="utf-8")) if reg_path.exists() else {"issued": [], "refused": []} def save_reg(): reg_path.parent.mkdir(parents=True, exist_ok=True) reg_path.write_text(json.dumps(reg, ensure_ascii=False, indent=2), encoding="utf-8") now = datetime.datetime.now().isoformat(timespec="seconds") if missing: rec = {"time": now, "holder": a.holder, "reason": "三律证据缺失: " + ",".join(missing)} reg["refused"].append(rec) save_reg() msg = f"⛔ 拒绝签发:三律证据缺失({'、'.join(missing)})— 已留痕台账" print(json.dumps({"issued": False, "holder": a.holder, "missing": missing, "note": msg}, ensure_ascii=False, indent=2) if a.json else msg) sys.exit(1) serial = len(reg["issued"]) + 1 cert = { "badge": BADGE, "serial": serial, "holder": a.holder, "issuer": ISSUER, "issued_at": now, "evidence_sha256": ev, } ``` ### Technical An ...[truncated 2426 chars]
- Remediation
- ## Remediation Suggestions 1. Define a strict schema for each evidence type and reject unknown or malformed structures. 2. Reject empty evidence values and require minimum semantic content. 3. Treat values beginning with `@` as mandatory file references. If the referenced file does not exist, is not a regular file, cannot be decoded, or exceeds an appropriate size limit, terminate with an error. 4. Require each evidence record to contain an explicit successful outcome rather than inferring success from a key prefix. 5. Authenticate trusted gate reports using digital signatures or keyed message authentication, with signer identity and trust policy validation. 6. Bind evidence to the holder, policy version, evaluation timestamp, and relevant artifact digest to prevent evidence reuse. 7. Validate that the three records represent distinct required laws and originate from approved evaluators. 8. Add negative tests covering empty strings, nonexistent files, `false` values, malformed JSON, duplicate keys, untrusted signers, and evidence belonging to another holder. 9. Document that a digest provides integrity identification only and is not proof of authenticity or successful evaluation.
