T09 · Insecure Skill Coding Practices
- Location
scripts/fetch_trends.sh:29- Finding
Arbitrary Python Code Execution Through the DELAY_MS Environment Variable
- Content
View full analysis
Vulnerability Details
File Location:
scripts/fetch_trends.sh, line 29
Vulnerability Type: Environment-variable injection into dynamically constructed Python source
Risk Level: HighVulnerable code:
bash delay_seconds() { # convert ms to fractional seconds for sleep python3 -c "print(${DELAY_MS}/1000.0)" 2>/dev/null || echo "1.5" }Technical Analysis
DELAY_MSis a documented, user-configurable environment variable. Its value is interpolated directly into the source-code string passed topython3 -c, without numeric validation or safe argument passing.Shell quoting prevents direct shell metacharacter interpretation inside this command, but it does not prevent Python-language injection. An attacker can supply a syntactically crafted value that closes or extends the intended
print()expression and introduces arbitrary Python statements.For example, a value shaped like the following demonstrates the injection principle:
text 0);__import__("os").system("ATTACKER_COMMAND");#This transforms the generated Python program into code equivalent to:
python print(0);__import__("os").system("ATTACKER_COMMAND");#/1000.0)The flaw is reachable through both
scripts/fetch_trends.shandscripts/full_run.sh, because the orchestrator preserves the caller's environment when invoking the fetcher.Attack Path
- An attacker gains control over
DELAY_MS, such as through an untrusted wrapper, CI configuration, automation environment, or copied execution command. - The attacker places Python syntax and a desired command in that variable.
- A user or Agent invokes
scripts/fetch_trends.shorscripts/full_run.sh. - Line 29 interpolates the malicious value into the
python3 -csource string. - Python executes the injected statements before the trend-fetching loop begins.
- The injected process inherits the Skill runner's user identity, environment, f ...[truncated 1132 chars]
- An attacker gains control over
- Remediation
View remediation
Remediation Suggestions
Validate
DELAY_MSbefore use and pass it to Python as data rather than embedding it in executable source:bash delay_seconds() { [[ "$DELAY_MS" =~ ^[0-9]+$ ]] || die "DELAY_MS must be a non-negative integer" python3 -c \ 'import sys; print(int(sys.argv[1]) / 1000.0)' \ "$DELAY_MS" }Alternatively, avoid Python entirely and perform validated conversion with shell formatting:
bash delay_seconds() { [[ "$DELAY_MS" =~ ^[0-9]+$ ]] || die "DELAY_MS must be a non-negative integer" printf '%d.%03d\n' \ "$((10#$DELAY_MS / 1000))" \ "$((10#$DELAY_MS % 1000))" }Additional hardening should include:
- Apply strict allowlist validation to all documented environment overrides.
- Require positive bounded integers for
PAGESandPAGE_SIZE. - Bound
DELAY_MSto a reasonable operational range to prevent denial of service through excessive sleep durations. - Allow only documented values for
SORT_MODEandTIMEFRAMES. - Continue passing values through positional arguments, standard input, or narrowly scoped environment variables rather than constructing executable code.
- Add regression tests using quotes, semicolons, parentheses, comments, newlines, and nonnumeric values to verify that malformed input is rejected without execution.
