T09 · Insecure Skill Coding Practices
- Location
- rules/02-截图流程.md:18
- Finding
- Temporary HTTP Server Exposes the Output Directory on All Network Interfaces<![CDATA[ ## Vulnerability Details **File Location**: `rules/02-截图流程.md`, lines 18-22 **Vulnerability Type**: Unrestricted network binding and directory exposure **Risk Level**: Medium ### Vulnerable Code ```bash □ 0. Start a temporary HTTP server if one is not already running. Start it from the HTML directory: python3 -m http.server 8899 --directory <HTML_DIRECTORY> & Then open http://localhost:8899/filename.html ``` The security-relevant command in the original file is: ```bash python3 -m http.server 8899 --directory <html所在目录> & ``` ### Technical Analysis Python's `http.server` binds to all available network interfaces by default. Although the documented browser URL uses `localhost`, the listening socket is not restricted to the loopback interface. The command serves the entire selected directory rather than only the intended HTML file. Every readable file under that directory can consequently be requested by another host that can reach TCP port 8899. The process is also placed in the background without PID tracking or guaranteed cleanup, increasing the chance that the service remains available after screenshot generation. No authentication, authorization, transport encryption, or directory isolation is applied. ### Attack Path 1. A user supplies an article or note containing sensitive information. 2. The Agent generates HTML in a working directory that may also contain other files. 3. The screenshot workflow starts `python3 -m http.server 8899 --directory ... &`. 4. Python listens on all interfaces, including a LAN or container-facing interface. 5. An attacker with network access discovers or predicts port 8899. 6. The attacker requests the generated HTML or another known file beneath the served directory. 7. The service may remain available because the workflow does not retain and terminate its PID. ### Impact Assessment This issue does not provide operating-system privilege escalation or arbitrary code execution. It can, however, gr ...[truncated 381 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Bind the server explicitly to loopback: ```bash python3 -m http.server 8899 \ --bind 127.0.0.1 \ --directory "$TEMP_OUTPUT_DIRECTORY" & SERVER_PID=$! ``` 2. Create a dedicated temporary directory and copy only the intended HTML file and required local assets into it. 3. Do not serve the conversation working directory or project root. 4. Record the exact server PID and terminate it reliably: ```bash cleanup() { if kill -0 "$SERVER_PID" 2>/dev/null; then kill "$SERVER_PID" wait "$SERVER_PID" 2>/dev/null || true fi rm -rf "$TEMP_OUTPUT_DIRECTORY" } trap cleanup EXIT INT TERM ``` 5. Use a randomly selected free port to reduce collisions. 6. Disable directory listings through a minimal custom handler or serve only an explicitly selected file. 7. Confirm that the browser navigates only to `127.0.0.1`, not a non-loopback hostname. ]]>
