invoke-ai/InvokeAI · critical
Parent directory references not allowed in subfolder path
Error message
Parent directory references not allowed in subfolder path
What it means
Any '/'-separated component equal to '..' in the subfolder is rejected because it references a parent directory, enabling classic directory traversal out of the outputs folder. Raises ValueError with the parent-directory message.
Source
Thrown at invokeai/app/services/image_files/image_files_disk.py:289
if not resolved_image_path.is_relative_to(resolved_base):
raise ValueError("Image path outside outputs folder, potential directory traversal detected")
return resolved_image_path
@staticmethod
def _validate_subfolder(subfolder: str) -> None:
"""Validates a subfolder path to prevent directory traversal while allowing controlled subdirectories."""
if not subfolder:
return
if "\\" in subfolder:
raise ValueError("Backslashes not allowed in subfolder path")
if subfolder.startswith("/"):
raise ValueError("Absolute paths not allowed in subfolder path")
parts = subfolder.split("/")
for part in parts:
if part == "..":
raise ValueError("Parent directory references not allowed in subfolder path")
if part == "":
raise ValueError("Empty path segments not allowed in subfolder path")
def validate_path(self, path: Union[str, Path]) -> bool:
"""Validates the path given for an image or thumbnail."""
path = path if isinstance(path, Path) else Path(path)
return path.exists()
def get_workflow(self, image_name: str, image_subfolder: str = "") -> str | None:
image = self.get(image_name, image_subfolder=image_subfolder)
workflow = image.info.get("invokeai_workflow", None)
if isinstance(workflow, str):
return workflow
return None
def get_graph(self, image_name: str, image_subfolder: str = "") -> str | None:
image = self.get(image_name, image_subfolder=image_subfolder)
graph = image.info.get("invokeai_graph", None)View on GitHub (pinned to 0b6a024f2f)
Solutions
- Remove or resolve '..' components from the subfolder before calling
- Use a fixed set of allowed subfolder names (allowlist) rather than free-form paths
- Normalize with PurePosixPath and reject if any part == '..'
Example fix
// before
sub = f'{user_board}/../images'
// after
sub = posixpath.normpath(user_board)
assert '..' not in PurePosixPath(sub).parts Defensive patterns
Strategy: validation
Validate before calling
from pathlib import PurePosixPath
def subfolder_is_safe(s: str) -> bool:
parts = PurePosixPath(s).parts
return bool(parts) and all(p not in ('..', '.', '') for p in parts) and '\\' not in s
assert subfolder_is_safe('2024/08') Type guard
def has_no_parent_refs(s: object) -> bool:
return isinstance(s, str) and '..' not in PurePosixPath(s).parts Try / catch
try:
service.save(data, name, image_subfolder=subfolder)
except ValueError as e:
if 'Parent directory' in str(e):
raise HTTPException(400, 'Subfolder may not reference parent directories') from e Prevention
- Never build subfolders from unvalidated user input
- Allowlist known-good subfolder names instead of free-form paths
- Run security tests covering '../' payloads against storage APIs
When it happens
Trigger: Passing image_subfolder like '../secrets', 'a/../b', or '../../etc' to get/save/get_path.
Common situations: User-controlled board names containing '..'; hand-built relative paths; API requests crafted to escape the outputs directory (security probing).
Related errors
- Cannot derive a safe filename for {url} from '{file_name}'
- Invalid image name, potential directory traversal detected
- only relative download paths accepted
- Image path outside outputs folder, potential directory trave
- Parent directory references not allowed in subfolder path
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/d2b82a76429b0732.
Report an issue: GitHub.