T09 · Insecure Skill Coding Practices
- Location
scripts/position_sizing.py:8- Finding
Position-Sizing Utility Does Not Enforce Financial Input and Risk Limits
- Content
View full analysis
") sys.exit(1) try: balance = float(sys.argv[1]) risk_percent = float(sys.argv[2]) stop_loss_dist = float(sys.argv[3]) size = calculate_position_size(balance, risk_percent, stop_loss_dist) print(f"{size:.8f}") ``` ### Technical Analysis The project documentation establishes a mandatory risk range of 1% to 2% per trade, including a statement that risk must never exceed 2%. The executable implementation does not enforce that constraint. It accepts any value that Python's `float()` function can parse for the account balance, risk percentage, and stop-loss distance. Only a non-positive stop-loss distance is handled, and that condition silently returns a position size of zero. The implementation does not reject: - Risk percentages above the documented 2% maximum. - Negative risk percentages. - Zero or negative account balances. - Non-finite values such as `nan`, `inf`, and `-inf`. - Extremely small positive stop-loss distances that generate excessively large position sizes. Because IEEE-754 non-finite values are accepted by `float()`, the program can print values such as `nan` or `inf` without raising the caught `ValueError`. A downstream trading component that trusts this program's output could therefore receive an invalid or dangerously oversized order quantity. ### Attack Path 1. An operator, automation system, or attacker controlling the command-line ar ...[truncated 1441 chars]- Remediation
View remediation
