T09 · Insecure Skill Coding Practices
- Location
scripts/bitpanda.sh:248- Finding
Arbitrary Command Execution Through Unvalidated --limit Arithmetic Evaluation
- Content
View full analysis
Vulnerability Details
File Location:
scripts/bitpanda.sh, lines 248–270
Vulnerability Type: Command injection through Bash arithmetic expansion
Risk Level: Highbash cmd_trades() { require_api_key local operation="" asset_type="" limit=5 from="" to="" while [ $# -gt 0 ]; do case "$1" in --operation) operation="$2"; shift 2;; --asset-type) asset_type="$2"; shift 2;; --limit) limit="$2"; shift 2;; --from) from="$2"; shift 2;; --to) to="$2"; shift 2;; *) die "Unknown option: $1";; esac done local tmpdir tmpdir=$(mktemp -d) _CLEANUP_DIRS+=("$tmpdir") # Fetch ticker for asset type mapping (type field: cryptocoin, metal, stock, etc.) fetch_all_ticker_prices > "$tmpdir/ticker.json" & local ticker_pid=$! # Fetch transactions, auto-paginating until we have enough matches # When asset_type filter is active, collect more since filtering happens post-enrichment local collect_limit=$limit if [ -n "$asset_type" ]; then collect_limit=$((limit * 10)); fiTechnical Analysis
The
--limitoption accepts an arbitrary string and stores it inlimitwithout validating that it is a positive integer. When--asset-typeis nonempty, line 270 evaluates that value as part of Bash arithmetic expansion:bash collect_limit=$((limit * 10))Bash can recursively interpret variable contents as arithmetic expressions. Arithmetic expressions can include array subscripts, and maliciously constructed subscripts can contain command substitutions. Consequently, this is not limited to malformed numeric input: a crafted
--limitvalue can cause a local command to execute.Quoting the value when it is initially assigned does not prevent this issue because the dangerous interpretation occurs later in the arithmetic context.
Attack Path
- The
BITPANDA_API_KEYenvironment variable is present, allowing `r ...[truncated 1474 chars]
- The
- Remediation
View remediation
Remediation Suggestions
Validate
--limitimmediately after parsing and before any arithmetic evaluation. Require a canonical positive decimal integer and impose a reasonable upper bound:bash [[ "$limit" =~ ^[1-9][0-9]*$ ]] || die "--limit must be a positive integer" (( 10#$limit <= 1000 )) || die "--limit must not exceed 1000" collect_limit=$((10#$limit)) if [[ -n "$asset_type" ]]; then collect_limit=$((10#$limit * 10)) fiAdditional hardening should include:
- Validate every CLI option according to its expected type and allowed values.
- Check that options requiring a value have another argument before referencing
$2. - Restrict
--operationto documented values such asbuyandsell. - Validate date parameters against an accepted ISO 8601 format.
- Reject control characters and unexpected syntax in identifiers and cursors.
- Add regression tests using malicious arithmetic inputs, including array-subscript command substitutions, and verify that no command executes.
- Run the Skill with the minimum filesystem, network, and environment access required for its read-only API functionality.
