T09 · Insecure Skill Coding Practices
- Location
scripts/audit_ppt.js:212- Finding
Arbitrary Command Execution Through a Crafted PPTX File Path
- Content
View full analysis
Vulnerability Details
File Location:
scripts/audit_ppt.js:212-253
Vulnerability Type: OS command injection through shell-based subprocess execution
Risk Level: HighVulnerable Code:
javascript const pythonScript = ` import sys try: from pptx import Presentation from pptx.util import Inches, Pt except ImportError: print("PYTHON_PPTX_NOT_INSTALLED") sys.exit(1) prs = Presentation(r"${pptxPath.replace(/\\/g, "\\\\")}") print(f"SLIDE_COUNT:{len(prs.slides)}") # Check each slide for size and content overflow for i, slide in enumerate(prs.slides): page_num = i + 1 for shape in slide.shapes: if shape.has_text_frame: try: x = shape.left / 914400 y = shape.top / 914400 w = shape.width / 914400 h = shape.height / 914400 if y + h > 5.5: print(f"OVERFLOW:p{page_num}:y={y:.2f},h={h:.2f},y+h={y + h:.2f}") if x + w > 9.8: print(f"RIGHT_OVERFLOW:p{page_num}:x={x:.2f},w={w:.2f},x+w={x + w:.2f}") except: pass print("PYTHON_AUDIT_DONE") `; try { const result = execSync(`python3 -c "${pythonScript.replace(/"/g, '\\"')}"`, { encoding: "utf8", timeout: 30000, });Technical Analysis
The PPTX path originates from a command-line argument and is inserted directly into dynamically generated Python source. The resulting Python program is then placed inside a shell command executed through
execSync().The implementation only doubles backslashes in the path and escapes double quotes in the final Python source. It does not neutralize shell substitutions such as
$()or backticks. Because string-basedexecSync()uses a shell by default, shell metacharacters embedded in a valid filename can be interpreted before Python starts.The preceding `fs.exi ...[truncated 1682 chars]
- Remediation
View remediation
Remediation Suggestions
- Eliminate shell interpretation by replacing string-based
execSync()withexecFileSync()orspawnSync()and passing arguments as an array. - Pass the PPTX path as a separate Python argument instead of embedding it in Python source:
javascript const { execFileSync } = require("child_process"); const pythonScript = ` import sys from pptx import Presentation pptx_path = sys.argv[1] prs = Presentation(pptx_path) print(f"SLIDE_COUNT:{len(prs.slides)}") `; const result = execFileSync( "python3", ["-c", pythonScript, pptxPath], { encoding: "utf8", timeout: 30000, shell: false, } ); - Verify with
fs.statSync()that the supplied path refers to a regular file. - Resolve the path with
path.resolve()and, when audits are restricted to a workspace, ensure the resolved path remains inside that approved directory. - Retain the
.pptxextension check as a file-type hint, but do not treat it as a security boundary. - Add regression tests using filenames containing spaces, quotes, dollar signs, parentheses, backticks, and newline characters.
- Eliminate shell interpretation by replacing string-based
