T09 · Insecure Skill Coding Practices
- Location
SKILL.md:31- Finding
Unsafe User-Value Interpolation Enables SQL and Shell Command Injection
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 31-35
Vulnerability Type: SQL injection and shell command injection
Risk Level: HighVulnerable Code
bash sqlite3 ~/.openclaw/data/bankroll.db \ "INSERT INTO bets (platform, sport, selection, bet_type, stake, odds, notes) VALUES ('PLATFORM', 'SPORT_KEY', 'SELECTION', 'BET_TYPE', STAKE, ODDS, 'NOTES');"Technical Analysis
The skill instructs the agent to replace uppercase placeholders directly within an SQL statement that is itself embedded in a double-quoted shell argument. No parameter binding, shell-safe argument handling, escaping, or input validation is specified.
Text fields such as
PLATFORM,SELECTION, andNOTESare enclosed in SQL single quotes. An attacker-controlled apostrophe can terminate the intended SQL string and append additional SQL statements or alter the original query. The numericSTAKEandODDSfields are inserted without quoting or type validation, providing additional SQL injection opportunities.The SQL statement is also placed inside shell double quotes. If substituted content contains shell expansion syntax such as command substitution, the shell can evaluate it before invoking
sqlite3. Merely escaping SQL single quotes would therefore not address the shell-injection layer.Attack Path
- An attacker or untrusted user asks the agent to log a bet containing crafted data in a platform, selection, notes, stake, or odds field.
- Following the skill instructions, the agent replaces the uppercase placeholder with that value verbatim.
- A value containing an SQL quote and additional syntax escapes the intended SQL literal, allowing unauthorized statements to be interpreted by SQLite.
- Alternatively, a value containing shell command-substitution syntax is placed inside the generated double-quoted shell argument.
- The shell evaluates that substitution before starting
sqlite3, executing the ...[truncated 1022 chars]
- Remediation
View remediation
Remediation Suggestions
-
Replace generated shell SQL with a dedicated implementation using Python's
sqlite3API and parameterized queries:python connection.execute( """ INSERT INTO bets (platform, sport, selection, bet_type, stake, odds, notes) VALUES (?, ?, ?, ?, ?, ?, ?) """, (platform, sport, selection, bet_type, stake, odds, notes), ) -
Pass values as data through a structured interface instead of constructing a shell command from user-controlled text.
-
Do not use
shell=True, shell-generated command strings,eval, or equivalent mechanisms. -
Validate
stakeandoddsas finite numeric values and enforce documented minimum and maximum bounds. -
Restrict fields such as platform, sport, and bet type to explicit allowlists where practical.
-
Apply length limits and reject control characters for free-text fields.
-
Execute database operations with the least-privileged operating-system account and restrictive database-file permissions.
-
Use transactions and handle database errors without retrying through dynamically modified commands.
-
Add tests containing apostrophes, quotes, command-substitution characters, SQL metacharacters, and unusually long input.
-
Correct and close the Markdown code fence, and provide schema initialization or migration instructions for the required
betstable.
-
