T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/agent_boarding_pass.py:25
- Finding
- Boarding passes are forgeable because integrity protection is unkeyed and evidence validation fails open<![CDATA[ ## Vulnerability Details **File Location**: `scripts/agent_boarding_pass.py:25-29, 34-49, 62, 100-115` **Vulnerability Type**: Cryptographically ineffective authenticity validation and insufficient evidence validation **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 def issue(a): 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] if missing: msg = "⛔ 拒绝签发:三律证据缺失(" + "、".join(missing) + ")" print(json.dumps({"issued": False, "agent": a.agent, "missing": missing, "note": msg}, ensure_ascii=False, indent=2) if a.json else msg) sys.exit(1) ``` ```python card["fingerprint"] = sha256_of(json.dumps(card, ensure_ascii=False, sort_keys=True)) ``` ```python miss = [k for k in ("pass_type", "agent", "issued_at", "expires_at", "allow", "evidence_sha256", "fingerprint") if k not in card] checks.append(("结构完整", not miss, "缺失字段: " + ",".join(miss) if miss else "字段齐全")) body = {k: card[k] for k in ("pass_type", "agent", "issued_at", "expires_at", "allow", "evidence_sha256") if k in card} checks.append(("指纹防篡改", bool(card.get("fingerprint")) and sha256_of(json.dumps(body, ensure_ascii=False, sort_keys=True)) == card.get("fingerprint"), "重算一致" if checks and sha256_of(json.dumps(body, ensure_ascii=Fa ...[truncated 3510 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Replace the unkeyed fingerprint with authenticated issuance: - Prefer an Ed25519 digital signature over a canonical card representation. - Alternatively, use HMAC-SHA-256 if every verifier can securely share the same secret. - Include an issuer identifier, signature algorithm, and key identifier in the card. - Configure verifiers with trusted public keys rather than accepting keys embedded only in the card. 2. Canonicalize signed data using a clearly specified serialization format. Ensure issuance and verification sign exactly the same fields and reject unknown or malformed security-critical fields where appropriate. 3. Fail closed for evidence references: - Require referenced evidence files to exist and be regular files. - Treat literal values as a separate, explicit input mode if they are genuinely supported. - Validate evidence against defined schemas and trusted provenance. - Bind evidence to the claimed agent and issuer. 4. During verification: - Require `pass_type == "lgd-agent-boarding-pass"`. - Require valid `l1-`, `l2-`, and `l3-` evidence entries. - Validate field types, including that `allow` is a list of permitted action identifiers. - Validate that `issued_at` and `expires_at` are well-formed and chronologically consistent. - Enforce an acceptable maximum TTL. - Reject cards issued unreasonably far in the future. - Verify the issuer signature before trusting identity, evidence, permissions, or expiration. 5. Clearly document that a plain SHA-256 digest provides no proof of issuer authenticity and must not be used as an authorization credential. ]]>
