T09 · Insecure Skill Coding Practices
- Location
scripts/process_book.sh:20- Finding
Unrestricted Extraction and Parsing of Untrusted EPUB Archives
- Content
View full analysis
]+>', ' ', html) txt = re.sub(r'\s+', ' ', txt).strip() if txt: # 只添加非空内容 parts.append(txt) except Exception as e: print(f"Warning: failed to read {fn}: {e}", file=sys.stderr) with open(out_path, 'w', encoding='utf-8') as out: out.write('\n\n'.join(parts)) PY ``` ### Technical Analysis The script treats an uploaded EPUB as a trusted ZIP archive and extracts it without first validating archive members. It does not reject: - Absolute paths or entries containing parent-directory traversal components. - Symbolic links or other non-regular file types. - Excessive archive member counts. - Excessive total uncompressed size. - Highly compressed files intended to exhaust disk space. - Files whose resolved paths fall outside the intended extraction directory. The Python processing stage then recursively finds every file ending in `.html` or `.xhtml` and opens it without checking whether it is a symbolic link or whether its canonical path remains under `TMP_DIR`. Consequently, an archive-created link with an XH ...[truncated 1704 chars]- Remediation
View remediation
