T09 · Insecure Skill Coding Practices
- Location
scripts/boof.sh:121- Finding
Arbitrary Python Code Execution Through Unsafely Interpolated Paths
- Content
View full analysis
Vulnerability Details
File Location:
scripts/boof.sh, lines 121-127
Vulnerability Type: Python source injection through an unquoted here-document
Risk Level: HighVulnerable Code
bash "$ODL_PYTHON" - 2>&1 <<PYEOF | grep -v "^Mar\|^INFO\|^WARNING" | sed 's/^/ /' || true import opendataloader_pdf opendataloader_pdf.convert( input_path=["$INPUT_FILE"], output_dir="$OUTPUT_DIR/", format="markdown" ) PYEOFTechnical Analysis
The here-document delimiter is not quoted, so the shell expands
INPUT_FILEandOUTPUT_DIRbefore sending the generated program to Python. Both variables can contain user-controlled text:INPUT_FILEis populated from a positional command-line argument.OUTPUT_DIRis populated from--output-dirorBOOF_OUTPUT_DIR.
These values are inserted directly between Python quotation marks without Python-string escaping. A value containing quotation marks and Python expressions can terminate the intended string literal and introduce executable Python syntax.
Shell-level quoting around
"$INPUT_FILE"elsewhere in the script does not protect this generated Python source. The|| truepipeline suffix also suppresses conversion errors, potentially making exploitation attempts less visible.Attack Path
- An attacker creates or supplies a document whose filename contains Python syntax, or persuades the user to invoke the script with a crafted
--output-dir. - The user or agent runs
boof.shon that path. - Lines 121-127 interpolate the crafted value into the Python program.
- The injected expression is parsed and evaluated by the configured ODL Python interpreter.
- The payload can invoke modules such as
osorsubprocessand execute operating-system commands with the privileges of the user running the Skill.
For example, a filename can be structured so that its injected portion closes the first list element and add ...[truncated 836 chars]
- Remediation
View remediation
Remediation Suggestions
Do not construct Python source by interpolating path values. Pass paths as positional arguments and use a quoted here-document:
bash "$ODL_PYTHON" - "$INPUT_FILE" "$OUTPUT_DIR" <<'PYEOF' import sys import opendataloader_pdf input_file = sys.argv[1] output_dir = sys.argv[2] opendataloader_pdf.convert( input_path=[input_file], output_dir=output_dir, format="markdown", ) PYEOFIn addition:
- Remove
|| trueso conversion failures are not silently ignored. - Validate that options requiring values actually have a following argument before reading
$2. - Reject embedded NUL or newline characters where appropriate.
- Canonicalize paths and apply output-directory restrictions if callers should not be able to write to arbitrary locations.
- Add regression tests using filenames containing quotes, backslashes, spaces, Unicode characters, newlines, and Python-like expressions.
- Remove
