T09 · Insecure Skill Coding Practices
- Location
SKILL.md:28- Finding
Predictable Shared Temporary Files Expose Sensitive Feishu Documents
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 28–38
Vulnerability Type: Predictable and insecure temporary-file handling
Risk Level: MediumVulnerable Code
markdown ### Step 2:保存原文到临时文件 将每份文档的 `markdown` 字段原始内容写入独立临时文件:/tmp/merge_doc_0.md ← 文档1原文 /tmp/merge_doc_1.md ← 文档2原文 /tmp/merge_doc_2.md ← 文档3原文 ...
text **重要:写入时不做任何修改、不压缩、不总结,原文是什么就写什么。**Related cleanup instructions in
references/chapter_parsing.md, lines 54–59:markdown ## 临时文件清理 合并完成后,AI 应清理临时文件: ```bash rm -f /tmp/merge_doc_*.mdtext The script reads these caller-supplied paths in `scripts/merge.py`, lines 36–49: ```python def merge(name_path_pairs: list[tuple[str, str]]) -> str: doc_parts_list: list[tuple[str, dict[int, str]]] = [] for name, path in name_path_pairs: try: with open(path, encoding="utf-8") as f: text = f.read() parts = extract_parts(text) doc_parts_list.append((name, parts)) except FileNotFoundError: print(f"警告:未找到文件 '{path}' (对应姓名: {name}),已跳过该文件。", file=sys.stderr) continue except Exception as e: print(f"警告:读取文件 '{path}' 时发生错误:{e},已跳过该文件。", file=sys.stderr) continueTechnical Analysis
The Skill directs the Agent to store the complete contents of potentially confidential weekly reports under deterministic names in the shared
/tmpdirectory. It does not require a private per-run directory, atomic exclusive creation, restrictive permissions, symlink protection, ownership verification, or secure lifecycle management.Predictable shared paths introduce several weaknesses:
- A local attacker can anticipate the filenames and monitor or read them if their permissions allow it.
- An attacker can pre-create a path as a symbolic link, potentially redirecting a naïve writer to another filesystem target.
- A local process can replace or modify a temporary document before
merge.pyreads it ...[truncated 2608 chars]
- Remediation
View remediation
Remediation Suggestions
- Create a unique private temporary directory for every run, for example with Python's
tempfile.TemporaryDirectory(), and ensure its permissions are0700. - Create each temporary file atomically with exclusive creation and permissions no broader than
0600. - Do not use deterministic names directly under the shared
/tmpdirectory. - Keep secure file handles open where practical rather than closing and reopening files by predictable paths.
- Reject symbolic links and non-regular files. Where supported, use
O_NOFOLLOW, then verify file type, ownership, and permissions withfstat. - Perform cleanup in a
finallyblock or use a temporary-directory context manager so cleanup occurs after success, errors, and exceptions. - Delete only the private per-run directory. Do not use
rm -f /tmp/merge_doc_*.md, which can affect unrelated or concurrent runs. - Avoid writing source documents to disk when possible. Pass content through protected standard input or perform parsing and merging in memory.
- Document the sensitivity and retention policy for fetched Feishu contents and ensure logs and error messages never include document bodies.
- Make the secure cleanup and file-creation requirements part of the primary workflow in
SKILL.md, rather than relying on an optional reference document.
- Create a unique private temporary directory for every run, for example with Python's
