T09 · Insecure Skill Coding Practices
- Location
scripts/verify_receipt.py:180- Finding
Incomplete SAR v0.1 Receipt Schema Validation
- Content
View full analysis
Vulnerability Details
File Location:
scripts/verify_receipt.py, lines 180-196
Vulnerability Type: Incomplete input and protocol validation
Risk Level: MediumVulnerable Code
python sig = receipt.get("sig") # Structural / prefix rules (ported from _sar_verify_receipt_v0_1). if not (isinstance(rid, str) and rid.startswith("sha256:")): errors.append("receipt_id missing required 'sha256:' prefix") if not (isinstance(sig, str) and sig.startswith("base64url:")): errors.append("sig missing required 'base64url:' prefix") if not (isinstance(kid, str) and kid.strip()): errors.append("verifier_kid missing") for field in _CORE_REQUIRED: if receipt.get(field) is None: errors.append(f"missing required core field: {field}") if errors: return result()Technical Analysis
The verifier checks whether required core fields are present, but it does not enforce the complete receipt schema documented in
spec/canonicalization.md.In particular, it does not validate:
- That
sar_versionis present and exactly identifies the supported protocol version. - That
verdictis one ofPASS,FAIL, orINDETERMINATE. - The documented types of
task_id_hash,confidence,reason_code, andts. - The allowed range and finiteness of
confidence. - That
task_id_hashandreceipt_idcontain correctly formed, fixed-length SHA-256 hexadecimal values. - That
tsis a valid ISO 8601 UTC timestamp. - Any defined constraints on
reason_code.
Cryptographic verification only establishes that the selected fields were signed by the corresponding private key. It does not establish that those fields conform to SAR v0.1. Consequently, a correctly signed but semantically malformed receipt can be returned with
valid: true.This conflicts with the claim in
SECURITY.mdthat a valid result means the receipt structure satisfies SAR v0.1 field and prefix expectations. Do ...[truncated 1766 chars]- That
- Remediation
View remediation
Remediation Suggestions
Implement strict schema validation before canonicalization and signature acceptance:
- Require
sar_versionand reject any value other than the explicitly supported version. - Enforce exact JSON types for every signed field. In Python, explicitly reject booleans where a numeric value is expected because
boolis a subclass ofint. - Restrict
verdicttoPASS,FAIL, orINDETERMINATE. - Validate
confidenceas a finite numeric value within the protocol-defined range. - Validate SHA-256 identifiers using an exact expression such as
^sha256:[0-9a-f]{64}$. - Parse
tsand require the protocol-defined ISO 8601 UTC representation. - Enforce the permitted
reason_codevalues or format. - Validate optional
counterpartyvalues consistently rather than silently excluding invalid types from the signed core. - Distinguish cryptographic authenticity from schema validity in the result, for example with separate
signature_validandschema_validfields. - Add negative tests for wrong versions, unknown verdicts, malformed hashes, invalid timestamps, non-finite numbers, incorrect JSON types, and out-of-range confidence values.
- Require
