T09 · Insecure Skill Coding Practices
- Location
archive_checker.py:120- Finding
Path Traversal Through Unsanitized Filename Components
- Content
View full analysis
:"/\\|?*]', '', title)[:30] timestamp = datetime.now().strftime('%Y%m%d') return f"{item_type}_{safe_title}_{record_id}_{timestamp}.md" ``` ```python cells = record.get('cells', {}) item_type = get_cell_value(cells, "XVSa9uv") if not item_type: print(f" [跳过] {record_id} 无事项类型") continue print(f" [处理] {item_type}: {record_id}") # 根据类型生成文档 if item_type == "问题": doc_content, title = generate_problem_report(cells, record_id) elif item_type == "需求": doc_content, title = generate_requirement_doc(cells, record_id) elif item_type == "任务": doc_content, title = generate_task_summary(cells, record_id) else: doc_content, title = generate_problem_report(cells, record_id) # 保存文档 filename = generate_doc_filename(item_type, title, record_id) filepath = os.path.join(DOCS_DIR, filename) with open(filepath, 'w', encoding='utf-8') as f: f.write(doc_content) ``` ### Technical Analysis The filename generator sanitizes only `title`. The `item_type` and `record_id` values are incorporated into the filename without validation. In particular, path separators, absolute paths, and traversal sequences remain permitted in `item_type`. The processing logic accepts any nonempty item type. Unknown values fall through to `generate_problem_report`, so an unexpected item type is not rejected before it reaches the filesystem sink. When a filename beginning with `/` is passed to `os.path.join`, the intended `DOCS_DIR` prefix is discarded. Relative components such as `../` can likewise cause the resolved path to escape the documentation directory. The script then opens the resulting path in write mode, ...[truncated 2218 chars]- Remediation
View remediation
