Skip to content

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.

fix: normalize paths in file router to prevent HTTPException with dotdot paths (#8425)

Dex Devlon31dfd43d5240
diff --git a/marimo/_server/file_router.py b/marimo/_server/file_router.py
index 7078c05f25..5f802a6a53 100644
--- a/marimo/_server/file_router.py
+++ b/marimo/_server/file_router.py
@@ -177,7 +177,8 @@ class ListOfFilesAppFileRouter(AppFileRouter):
self._allow_single_file_key = allow_single_file_key
self._allow_dynamic = allow_dynamic
self._allowed_paths = {
- MarimoPath(file.path).absolute_name for file in files
+ str(normalize_path(Path(MarimoPath(file.path).absolute_name)))
+ for file in files
}
@property
@@ -257,7 +258,9 @@ class ListOfFilesAppFileRouter(AppFileRouter):
"""
if not self._allow_dynamic:
return
- self._allowed_paths.add(MarimoPath(filepath).absolute_name)
+ self._allowed_paths.add(
+ str(normalize_path(Path(MarimoPath(filepath).absolute_name)))
+ )
class LazyListOfFilesAppFileRouter(AppFileRouter):
diff --git a/tests/_server/test_file_router.py b/tests/_server/test_file_router.py
index e9cda6d65e..e163593595 100644
--- a/tests/_server/test_file_router.py
+++ b/tests/_server/test_file_router.py
@@ -216,6 +216,30 @@ class TestAppFileRouter(unittest.TestCase):
assert file_manager.filename.startswith(self.test_dir)
assert "nested" in file_manager.filename
+ def test_list_of_files_resolves_dotdot_in_path(self):
+ """Paths with '..' components should resolve correctly.
+
+ Regression test for https://github.com/marimo-team/marimo/issues/8414
+ """
+ # Build a path with '..' that resolves to test_file1
+ # e.g. /tmp/dir/nested/../file.py -> /tmp/dir/file.py
+ dotdot_path = os.path.join(
+ self.nested_dir, "..", os.path.basename(self.test_file1.name)
+ )
+ files = [
+ MarimoFile(
+ name="test.py",
+ path=dotdot_path,
+ last_modified=os.path.getmtime(self.test_file1.name),
+ )
+ ]
+ router = ListOfFilesAppFileRouter(files)
+ key = router.get_unique_file_key()
+ assert key is not None
+ resolved = router.resolve_file_path(key)
+ assert resolved is not None
+ assert os.path.exists(resolved)
+
def test_flatten_files() -> None:
root = FileInfo(