T09 · Insecure Skill Coding Practices
- Location
scripts/server.py:63- Finding
Project Root Exposed Through an Unauthenticated Network Server
- Content
View full analysis
Vulnerability Details
File Location:
scripts/server.py, lines 63-70
Vulnerability Type: Unrestricted network binding and excessive file-serving scope
Risk Level: HighVulnerable Code
python def run_server_forever(port, base_dir): """Run the server synchronously.""" os.chdir(base_dir) # Save server info os.makedirs(os.path.join(base_dir, 'tmp'), exist_ok=True) with open(get_server_info_file(), 'w') as f: json.dump({'port': port}, f) handler = CustomHTTPRequestHandler with socketserver.TCPServer(("", port), handler) as httpd:Technical Analysis
The process changes its working directory to the project root and uses
SimpleHTTPRequestHandler, which serves files underneath the current working directory. The server then binds to an empty host address, equivalent to all available network interfaces rather than loopback only.Although
ensure_server_running()returns a URL using127.0.0.1, that returned URL does not constrain the listening socket. Hosts capable of reaching the machine on the selected port may request project files without authentication.The project root may contain
workspace.db,config.txt, generated reports, chart configurations, cached geographic data, source files, and other business data. Serving the complete root therefore exceeds the legitimate requirement to expose generated chart HTML and static ECharts assets.Attack Path
- A user generates a chart, causing the HTTP server to start on a port between 8000 and 8099.
- The service listens on all network interfaces.
- An attacker on a reachable network discovers the open port through scanning or local network observation.
- The attacker requests sensitive paths such as
/workspace.db,/config.txt,/references/geo_cache.json, or files under/outputs/. SimpleHTTPRequestHandlerreturns accessible files without authentication.- The att ...[truncated 564 chars]
- Remediation
View remediation
Remediation Suggestions
- Bind the service explicitly to loopback:
python with socketserver.TCPServer(("127.0.0.1", port), handler) as httpd: - Do not change the serving directory to the project root. Use a dedicated public directory containing only generated chart HTML and approved static assets.
- Implement an allowlist for URL paths and reject requests for databases, configuration files, dotfiles, source files, and metadata.
- Add an unpredictable per-session access token if browser access is required.
- Add security tests confirming that
/workspace.db,/config.txt, and directory listings cannot be retrieved. - Run the server with minimal filesystem permissions and disable directory listing.
- Bind the service explicitly to loopback:
