fix: block path traversal in static handler
The LAN-bound HTTP server joined the raw URL path onto the project dir, so /../../.ssh/id_ed25519 (and %2e%2e variants) served any file the user could read. Resolve and require the path stay inside the project. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -102,8 +102,10 @@ class WorkbenchServer:
|
||||
async def static_handler(request):
|
||||
proj = request.app["project_name"]
|
||||
path = request.match_info.get("path", "index.html") or "index.html"
|
||||
file_path = project_path(proj, self.workbench_dir) / path
|
||||
if not file_path.exists():
|
||||
root = project_path(proj, self.workbench_dir).resolve()
|
||||
file_path = (root / path).resolve()
|
||||
# served on the LAN — never let "../" escape the project dir
|
||||
if not file_path.is_relative_to(root) or not file_path.is_file():
|
||||
return web.Response(status=404, text="Not found")
|
||||
return web.FileResponse(file_path)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user