Skip to content

Conversation

@mscolnick
Copy link
Contributor

When users opened tutorials from the UI (top-right menu), they received an "Access denied" error because tutorial files are created in temp directories that are outside the allowed directory for directory-based file routers.

The CLI command marimo tutorial intro worked because it creates a ListOfFilesAppFileRouter specifically for that tutorial file, which doesn't perform directory validation.

Solution

Added temp directory tracking to LazyListOfFilesAppFileRouter to allow access to files in registered temp directories:

Fixes #7424

When users opened tutorials from the UI (top-right menu), they received an "Access denied" error because tutorial files are created in temp directories that are outside the allowed directory for directory-based file routers.

The CLI command `marimo tutorial intro` worked because it creates a `ListOfFilesAppFileRouter` specifically for that tutorial file, which doesn't perform directory validation.

### Solution

Added temp directory tracking to `LazyListOfFilesAppFileRouter` to allow access to files in registered temp directories:

Fixes #7424
@vercel
Copy link

vercel bot commented Dec 11, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
marimo-docs Ready Ready Preview Comment Dec 12, 2025 0:30am

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an "Access denied" error that occurred when users opened tutorials from the UI's top-right menu. The issue arose because tutorial files are created in temp directories outside the allowed base directory, causing directory-based file routers to reject access. The CLI command marimo tutorial intro worked because it uses a different router type that doesn't perform directory validation.

The solution adds temp directory tracking to LazyListOfFilesAppFileRouter:

  • New methods register_temp_dir() and is_file_in_allowed_temp_dir() manage allowed temp directories
  • Modified get_file_manager() to skip directory validation for files in registered temp directories
  • Tutorial endpoint now registers its temp directory with the file router when using directory-based routing

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
marimo/_server/file_router.py Added temp directory tracking to LazyListOfFilesAppFileRouter with register_temp_dir() and is_file_in_allowed_temp_dir() methods, and modified get_file_manager() to bypass validation for temp directory files
marimo/_server/api/endpoints/home.py Updated tutorial endpoint to register temp directories with the file router when using LazyListOfFilesAppFileRouter
tests/_server/test_file_router.py Added unit tests for temp directory registration and validation bypass behavior
tests/_server/api/endpoints/test_home.py Added integration test verifying tutorial files remain accessible after being opened

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +227 to +228
self._allowed_temp_dirs.add(normalized_path)
LOGGER.debug("Registered allowed temp directory: %s", normalized_path)
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The _allowed_temp_dirs set is mutated without synchronization, which could lead to race conditions when multiple tutorial endpoints are called concurrently. While Python's GIL provides some protection, iterating over the set in is_file_in_allowed_temp_dir (line 244) while it's being modified in register_temp_dir (line 227) can still cause RuntimeError. Consider using a thread-safe data structure or adding proper synchronization.

Copilot uses AI. Check for mistakes.
@mscolnick mscolnick merged commit 887af02 into main Dec 12, 2025
38 of 41 checks passed
@mscolnick mscolnick deleted the ms/tutorial branch December 12, 2025 22:02
@Light2Dark Light2Dark added the bug Something isn't working label Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't open any tutorials in Tutorials menu

3 participants