T09 · Insecure Skill Coding Practices
- Location
scripts/fear-greed.sh:7- Finding
Remote API Data Is Evaluated in Bash Arithmetic Without Validation
- Content
View full analysis
- Remediation
View remediation
= 0 and . <= 100)' <<<"$DATA"); then printf '%s\n' "Error: API returned an invalid fear-and-greed value." >&2 exit 1 fi ``` 2. Alternatively, apply a strict shell-level decimal validation and range check: ```bash if [[ ! $VALUE =~ ^[0-9]+$ ]] || (( VALUE < 0 || VALUE > 100 )); then printf '%s\n' "Error: value must be an integer from 0 to 100." >&2 exit 1 fi ``` 3. Convert validated input explicitly as base 10 before using it: ```bash VALUE_NUM=$((10#$VALUE)) BAR_FILLED=$((VALUE_NUM / 5)) BAR_EMPTY=$((20 - BAR_FILLED)) ``` 4. Harden network handling with failure detection and time limits: ```bash if ! DATA=$(curl --fail --silent --show-error \ --connect-timeout 5 --max-time 15 \ "$PRISM_URL/market/fear-greed"); then printf '%s\n' "Error: failed to retrieve market data." >&2 exit 1 fi ``` 5. Validate `.label` as a string and constrain its length before displaying it. Consider using a locally derived label based on the validated numeric value rather than trusting remote display content. 6. Add automated tests covering strings, objects, arrays, null values, negative values, values above 100, extremely large integers, and crafted arithmetic expressions. ]]>
