T09 · Insecure Skill Coding Practices
- Location
scripts/dorar_search.sh:12- Finding
Arbitrary Python Code Execution Through Unsafely Embedded Search Query
- Content
View full analysis
Vulnerability Details
File Location:
scripts/dorar_search.sh, lines 12–13
Vulnerability Type: Python code injection
Risk Level: HighVulnerable Code
bash # URL encode the query ENCODED=$(python3 -c "import urllib.parse; print(urllib.parse.quote('$QUERY'))")Technical Analysis
The script interpolates the user-controlled
QUERYvalue directly into source code passed topython3 -c. Although the shell command is enclosed in double quotes, the generated Python program places the query inside a single-quoted Python string.A query containing a single quote can terminate that Python string. The attacker can then append arbitrary Python statements and comment out the remaining expected syntax. The resulting statements execute locally with the privileges of the user running the Skill.
The intended URL-encoding operation only requires passing the query as data. Converting it into executable source code violates least-privilege design and creates an unnecessary local code-execution channel.
Attack Path
- An attacker supplies, or persuades a user or Agent to submit, a malicious hadith search query.
- The shell expands the query into the argument passed to
python3 -c. - A payload shaped like the following terminates the expected Python string and injects a new statement:
text '); __import__('os').system('ATTACKER_COMMAND'); #- Python parses the injected content as executable code.
ATTACKER_COMMANDruns before the request todorar.netis made.
The exact payload may require adjustment to preserve valid Python syntax, but no separate shell metacharacter injection is required because the vulnerable boundary is the dynamically generated Python source.
Impact Assessment
Successful exploitation provides arbitrary local code execution under the account that invoked the Skill. The attacker can consequently:
- Read files and credentials accessible to that account.
- Create, modify, or delete user-accessible ...[truncated 861 chars]
- Remediation
View remediation
Remediation Suggestions
Pass the query to Python as a data argument rather than interpolating it into executable source code:
bash ENCODED=$( python3 -c 'import sys, urllib.parse; print(urllib.parse.quote(sys.argv[1]))' \ "$QUERY" )Additional hardening measures:
- Enable strict shell behavior near the beginning of the script:
bash set -euo pipefail- Check that required executables such as
python3andcurlare available before use. - Configure
curlto report HTTP and transport failures rather than silently returning unusable content:
bash curl --fail --silent --show-error --location ...- Consider applying reasonable connection and total-request timeouts.
- Add regression tests containing single quotes, double quotes, semicolons, newlines, shell metacharacters, and Python syntax to verify that every query is treated solely as data.
- Keep the current model in which the API response is parsed by a fixed, bundled parser; do not pipe remote responses into a shell or interpreter as executable code.
