T09 · Insecure Skill Coding Practices
- Location
SKILL.md:70- Finding
Security-Critical Validation Implemented with Removable Python Assertions
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 70–77
Vulnerability Type: Insecure validation guidance
Risk Level: MediumComplete Code Snippet
python ### 5. Assertion Density Include defensive assertions documenting expectations. ```python def transfer_funds(from_acct, to_acct, amount): assert from_acct != to_acct, "Cannot transfer to same account" assert amount > 0, "Transfer amount must be positive" assert from_acct.balance >= amount, "Insufficient funds" # ... implementationTechnical Analysis
The skill recommends Python
assertstatements to enforce essential financial transaction rules, including positive transfer amounts, distinct source and destination accounts, and sufficient funds.Python assertions are intended for debugging and internal consistency checks, not security controls or business-rule validation. They are removed when Python runs with optimization enabled, such as through
python -O,python -OO, or an applicablePYTHONOPTIMIZEsetting. Under those conditions, none of the displayed checks execute.Because this guidance is explicitly presented for safety-critical and financial code, adopting the pattern could cause production behavior to differ from tested behavior and leave transaction-integrity constraints unenforced.
Attack Path
- A developer or coding agent follows the skill and implements financial validation using
assert. - The application is deployed with Python optimization enabled.
- Python removes the assertion statements from the executed bytecode.
- An attacker submits a prohibited transaction, such as a negative amount, an underfunded transfer, or a same-account transfer.
- If the omitted implementation performs no independent validation, processing continues and the intended financial invariants may be violated.
Impact Assessment
This issue does not directly grant operating-system privileges. Its scope is the application and data governed by ...[truncated 339 chars]
- A developer or coding agent follows the skill and implements financial validation using
- Remediation
View remediation
Remediation Suggestions
Replace security-sensitive and business-rule assertions with unconditional runtime validation:
python def transfer_funds(from_acct, to_acct, amount): if from_acct == to_acct: raise ValueError("Source and destination accounts must differ") if amount <= 0: raise ValueError("Transfer amount must be positive") if from_acct.balance < amount: raise InsufficientFundsError("Insufficient funds") # ... implementationUpdate the skill to clearly distinguish between:
- Explicit validation for untrusted input, authorization decisions, financial rules, and safety constraints.
- Assertions used only for internal invariants whose removal cannot change security or business correctness.
Also recommend centralized validation, domain-specific exceptions, atomic transaction handling, authorization checks, concurrency-safe balance verification, and tests executed both with and without Python optimization.
