A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: path validation test and public asset logic (#7688)
Myles Scolnickb43042afd6a1
diff --git a/marimo/_server/api/endpoints/assets.py b/marimo/_server/api/endpoints/assets.pyindex 394bc47a29..ad24df8db6 100644--- a/marimo/_server/api/endpoints/assets.py+++ b/marimo/_server/api/endpoints/assets.py@@ -309,16 +309,15 @@ async def serve_public_file(request: Request) -> Response:else:notebook_dir = Path.cwd()public_dir = notebook_dir / "public"- file_path = (public_dir / filepath).resolve()+ file_path = public_dir / filepath# Security check: ensure file is inside public directorytry:- validator = PathValidator(public_dir)- validator.validate_file_access(file_path)+ PathValidator().validate_inside_directory(public_dir, file_path)except HTTPException:return Response(status_code=403, content="Access denied")- if file_path.is_file() and not file_path.is_symlink():+ if file_path.is_file():return FileResponse(file_path)raise HTTPException(status_code=404, detail="File not found")diff --git a/tests/_server/api/endpoints/test_assets.py b/tests/_server/api/endpoints/test_assets.pyindex 5a1a623f9f..bb6706c366 100644--- a/tests/_server/api/endpoints/test_assets.py+++ b/tests/_server/api/endpoints/test_assets.py@@ -201,7 +201,7 @@ def test_public_file_security(client: TestClient) -> None:# Test symlink attemptresponse = client.get("/public/symlink.txt", headers=headers)- assert response.status_code == 403+ assert response.status_code == 200finally:# Cleanupdiff --git a/tests/_server/api/endpoints/test_files.py b/tests/_server/api/endpoints/test_files.pyindex 0db75ce036..ae9e8861ee 100644--- a/tests/_server/api/endpoints/test_files.py+++ b/tests/_server/api/endpoints/test_files.py@@ -96,8 +96,8 @@ def test_read_code_in_run_mode_without_include_code(headers=HEADERS,json={},)- # Should be denied 403 (forbidden)- assert response.status_code == 403+ # Should be denied 401 (unauthorized) or 403 (forbidden)+ assert response.status_code in [401, 403]@pytest.mark.flaky(reruns=5)