T09 · Insecure Skill Coding Practices
- Location
scripts/create_jd_price_excel.py:166- Finding
Hardcoded Output Path Can Overwrite a File Outside the Workspace
- Content
View full analysis
Vulnerability Details
File Location:
scripts/create_jd_price_excel.py, lines 166-167
Vulnerability Type: Hardcoded, unvalidated output path and silent file replacement
Risk Level: Mediumpython output_path = "/Users/wuhaorui/WorkBuddy/本地虾/电脑配置京东价格表.xlsx" wb.save(output_path)Technical Analysis
The script saves its generated workbook to a developer-specific absolute path. It does not derive the destination from the active workspace, accept a caller-supplied path, verify that the destination remains within an authorized directory, or check whether a file already exists.
Workbook.save()replaces an existing file at the destination without requesting confirmation. Therefore, if the hardcoded directory exists and is writable, invoking the script can modify or destroy a preexisting workbook outside the project workspace. This also conflicts withSKILL.md, which states that the generated file should be saved in the workspace root.Exploitation depends on the fixed destination existing and being writable by the account running the script. The issue does not provide privilege escalation and does not allow an external user to select an arbitrary target path.
Attack Path
- A user or agent invokes the bundled script to generate the advertised Excel report.
- The script ignores the current project or workspace location and selects the hardcoded absolute destination.
- The operating system resolves the destination under
/Users/wuhaorui/WorkBuddy/本地虾/. - If
电脑配置京东价格表.xlsxalready exists and is writable,wb.save(output_path)silently replaces it. - If the directory is unavailable or not writable, execution fails instead, preventing normal delivery of the generated report.
Impact Assessment
The script can overwrite one specific file using the existing filesystem privileges of the process. The affected scope is limited to the hardcoded destination; there is no evidence of elevated pr ...[truncated 341 chars]
- Remediation
View remediation
Remediation Suggestions
- Accept the output destination as an explicit command-line argument or function parameter.
- Default to a safe filename under the current workspace rather than a developer-specific absolute path.
- Resolve the destination with
pathlib.Path.resolve()and verify that it is contained within the authorized workspace. - Check whether the destination already exists and require explicit overwrite authorization before replacing it.
- Return a clear error when the parent directory is missing or unauthorized.
- Consider creating the workbook in the destination directory using a uniquely named temporary file and atomically renaming it after successful generation.
Example hardening pattern:
python from pathlib import Path workspace = Path.cwd().resolve() output_path = (workspace / "jd-price-report.xlsx").resolve() if workspace not in output_path.parents: raise ValueError("Output path must remain inside the workspace") if output_path.exists(): raise FileExistsError(f"Refusing to overwrite existing file: {output_path}") wb.save(output_path)
