T09 · Insecure Skill Coding Practices
Warning
- Location
- skills.md:237
- Finding
- Security-Relevant Input Validation Uses Removable Python Assertions<![CDATA[ ## Vulnerability Details **File Location**: `skills.md:237-239, 338-340, 389-405`; duplicated in `CS-RV_Protocol_Whitepaper.md:553-554, 607-609, 636-651` **Vulnerability Type**: Validation bypass through Python assertions **Risk Level**: Medium ### Vulnerable Code ```python # skills.md:237-239 assert len(coordinates) > 0, "Coordinates cannot be empty" assert 0 <= confidence <= 1, f"Confidence must be in [0,1], got {confidence}" assert observer_id, "Observer ID required" ``` Additional security-relevant checks use the same unsafe pattern: ```python # skills.md:338-340 assert state_hash in self.state_ledger, f"State {state_hash} not found" assert constraint_id in self.constraint_registry, f"Constraint {constraint_id} not found" assert 0 <= severity <= 1, f"Severity must be in [0,1], got {severity}" ``` ```python # skills.md:389-405 assert state_hash in self.state_ledger, f"State {state_hash} not found" state = self.state_ledger[state_hash] coords = state.coordinates assert all(0 <= d < len(coords) for d in target_dims), \ f"Invalid target dimensions {target_dims} for {len(coords)}D state" if projection_type == "orthogonal": projected = [coords[i] for i in target_dims] else: raise ValueError(f"Unknown projection type: {projection_type}") assert self._estimate_entropy(projected) <= self._estimate_entropy(coords), \ "Entropy increased during projection!" ``` ### Technical Analysis Python assertions are debugging constructs, not reliable runtime validation. Running the interpreter with optimization enabled, such as `python -O`, removes all `assert` statements. Consequently, the documented implementation may accept empty coordinate arrays, invalid confidence or severity values, and empty observer identifiers. Checks that references exist and projection dimensions are valid are also removed. This conflicts with the document's characterization of the implementation as production-ready. The same design is duplicated in the whitepap ...[truncated 1255 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Replace every security-relevant assertion with unconditional validation: ```python if not coordinates: raise ValueError("Coordinates cannot be empty") if not 0 <= confidence <= 1: raise ValueError(f"Confidence must be in [0,1], got {confidence}") if not observer_id: raise ValueError("Observer ID required") ``` 2. Validate references before accessing dictionaries: ```python if state_hash not in self.state_ledger: raise KeyError(f"State {state_hash} not found") ``` 3. Validate that projection dimensions are integers, non-negative, in range, and subject to an appropriate maximum count. 4. Retain assertions only for internal conditions that cannot be influenced by untrusted data. 5. Add automated tests that run under both standard Python and `python -O`. 6. Apply the same corrections to both `skills.md` and `CS-RV_Protocol_Whitepaper.md` so implementers do not copy an unsafe variant. ]]>
