fix(webui): allow media directory access when restrictToWorkspace is enabled

Add get_media_dir() as an extra allowed root in file_preview path resolution so uploaded images and documents remain previewable even with workspace restrictions on. Closes #5028
This commit is contained in:
seteiro
2026-07-24 00:30:49 +08:00
committed by chengyongru
parent 78f4c132d9
commit 4490f8cfe4
+3
View File
@@ -7,6 +7,7 @@ from pathlib import Path
from typing import Any
from urllib.parse import unquote, urlparse
from nanobot.config.paths import get_media_dir
from nanobot.security.workspace_access import WorkspaceScope
from nanobot.security.workspace_policy import WorkspaceBoundaryError, resolve_allowed_path
@@ -86,10 +87,12 @@ def _resolve_preview_path(raw_path: str | None, *, scope: WorkspaceScope) -> Pat
raise WebUIFilePreviewError(400, "path is too long")
try:
extra_roots = [get_media_dir()] if scope.restrict_to_workspace else None
resolved = resolve_allowed_path(
path,
workspace=scope.project_path,
allowed_root=scope.project_path if scope.restrict_to_workspace else None,
extra_allowed_roots=extra_roots,
strict=True,
)
except FileNotFoundError as e: