T09 · Insecure Skill Coding Practices
- Location
scripts/gas_tracker.py:217- Finding
Alert Threshold Violation Returns a Successful Exit Status
- Content
View full analysis
Vulnerability Details
File Location:
scripts/gas_tracker.py, lines 217-223
Vulnerability Type: Incorrect exit-status handling in security-relevant automation
Risk Level: MediumThe documented behavior in
SKILL.mdstates that alert mode should exit with status0when the standard gas price is below the specified threshold and status1when it is above the threshold. However, the implementation exits with status0in both cases.python def check_alert(data: dict, threshold: float): avg = data["standard"] if avg > threshold: print(f"ALERT: Standard gas ({avg:.1f} Gwei) exceeds threshold ({threshold} Gwei)") else: print(f"OK: Standard gas ({avg:.1f} Gwei) is below threshold ({threshold} Gwei)") sys.exit(0)Technical Analysis
Shell automation commonly uses process exit statuses as control-flow signals. A status of
0indicates success, while a nonzero status indicates failure or an unmet condition. Becausecheck_alert()unconditionally invokessys.exit(0), callers cannot distinguish an acceptable gas price from one that exceeds the configured threshold.This directly contradicts the documented contract in
SKILL.mdand breaks the supplied automation pattern:bash python scripts/gas_tracker.py --alert 30 && echo "Gas is low, good to swap!" || echo "Gas too high"When the standard gas price exceeds 30 Gwei, the program prints an alert but still returns success. The shell therefore executes the success branch and reports that gas is low. Any financial operation attached to that branch would also be executed.
Attack Path
- A user or scheduled task invokes
gas_tracker.py --alert GWEIand relies on its exit status. - One of the configured remote gas APIs supplies a standard gas price above the threshold, whether due to legitimate network congestion, erroneous data, or compromised upstream data.
- `ch ...[truncated 871 chars]
- A user or scheduled task invokes
- Remediation
View remediation
Remediation Suggestions
Return a nonzero status when the threshold is exceeded and status
0otherwise:python def check_alert(data: dict, threshold: float): avg = data["standard"] if avg > threshold: print( f"ALERT: Standard gas ({avg:.1f} Gwei) " f"exceeds threshold ({threshold} Gwei)" ) sys.exit(1) print( f"OK: Standard gas ({avg:.1f} Gwei) " f"is below threshold ({threshold} Gwei)" ) sys.exit(0)Additionally:
- Add automated tests for prices below, equal to, and above the threshold.
- Explicitly define whether equality is acceptable. The current comparison treats equality as acceptable, while the message says “below”; either change the message to “does not exceed” or change the comparison to match the intended policy.
- Add an integration test that executes the documented shell example and verifies that the correct branch is selected.
- Treat upstream API data as advisory and require additional validation before attaching irreversible financial operations to this command.
