T09 · Insecure Skill Coding Practices
- Location
SKILL.md:33- Finding
Command Injection Risk from Unsafe Shell Interpolation of User-Supplied PromQL Queries
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md:33-36andSKILL.md:54-57
Vulnerability Type: Shell command injection
Risk Level: HighVulnerable Code
SKILL.md:33-36:bash python3 devops-skills-plugin/skills/promql-validator/scripts/validate_syntax.py "<query>"SKILL.md:54-57:bash python3 devops-skills-plugin/skills/promql-validator/scripts/check_best_practices.py "<query>"Technical Analysis
The documented workflow instructs the agent to substitute a user-provided PromQL query directly into a shell command. Wrapping the value in double quotes does not safely neutralize shell syntax if the query contains an embedded double quote.
If the agent constructs a command string by replacing
<query>and executes it through a shell, an attacker can terminate the quoted argument and introduce shell operators. The shell would then interpret the injected text as commands rather than passing the entire value to the Python script as one argument.The vulnerability depends on the documented command being executed through a shell or equivalent string-based command interface. The Python validators themselves use
sys.argv[1]and do not execute the query. The test helper inscripts/test_validators.py:40-47also demonstrates a safe argument-array invocation. Therefore, the unsafe behavior is specifically in the skill's documented invocation pattern.Attack Path
-
An attacker provides a PromQL query containing a closing double quote, shell separators, and a trailing comment marker. A conceptual payload is:
text "; attacker_command; # -
The agent replaces the documented
<query>placeholder with the attacker-controlled text. -
The resulting command resembles:
bash python3 devops-skills-plugin/skills/promql-validator/scripts/validate_syntax.py ""; attacker_command; #" -
If the agent executes this string through a shell, the shell treats the semicolons as ...[truncated 1017 chars]
-
- Remediation
View remediation
Remediation Suggestions
-
Do not construct a shell command by interpolating the query. Invoke the validator through an argument-array API:
python subprocess.run( [sys.executable, validator_path, query], shell=False, check=False, capture_output=True, text=True, ) -
Update
SKILL.mdto mandate structured process invocation. Explicitly state that the query must be passed as one argument and that agents must not useshell=True,eval, or a concatenated command string. -
Prefer standard input for untrusted queries where the execution environment cannot guarantee argument-array semantics. The scripts can be extended to accept input from stdin:
python query = sys.stdin.read() -
Add regression tests using queries containing double quotes, semicolons, command substitutions, newlines, backticks, and shell redirection characters. Confirm that all content reaches the validator as data and that no secondary process executes.
-
Use the existing safe test pattern as the documented implementation model.
scripts/test_validators.py:40-47invokes Python with a list of arguments and does not enable shell processing. -
Apply least privilege to the validation process so that any future command-execution defect has limited filesystem, credential, and network impact.
-
