invoke-ai/InvokeAI · error
Absolute paths not allowed in subfolder path
Error message
Absolute paths not allowed in subfolder path
What it means
_validate_subfolder rejects subfolders that start with '/', i.e. absolute paths, to prevent escaping the outputs folder entirely. Only relative subfolder names under the base folder are allowed.
Source
Thrown at invokeai/app/services/image_files/image_files_disk.py:285
# Ensure the image path is within the base folder to prevent directory traversal
resolved_base = base_folder.resolve()
resolved_image_path = image_path.resolve()
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 NoneView on GitHub (pinned to 0b6a024f2f)
Solutions
- Convert to relative: strip the known base prefix before calling
- Use only bare relative names like '2024/08'
- Validate at the boundary that subfolder.startswith('/') is false and reject
Example fix
// before
sub = '/home/user/outputs/2024'
// after
sub = '2024' # or sub = os.path.relpath(p, base).replace('\\', '/') Defensive patterns
Strategy: validation
Validate before calling
from pathlib import PurePosixPath
def is_relative_subfolder(s: str) -> bool:
return bool(s) and not s.startswith('/') and '\\' not in s
if not is_relative_subfolder(sub): raise ValueError('subfolder must be relative, /-separated') Type guard
def is_relative_subfolder(s: object) -> bool:
return isinstance(s, str) and s != '' and not s.startswith('/') Try / catch
try:
service.get(name, image_subfolder=subfolder)
except ValueError as e:
if 'Absolute paths' in str(e):
sub = posixpath.relpath(sub, base) if sub.startswith(base) else ''
service.get(name, image_subfolder=sub) Prevention
- Store only relative subfolder names in configs and metadata
- Convert file-dialog results to paths relative to the outputs folder
- Reject absolute paths in user-facing board/subfolder inputs
When it happens
Trigger: Passing image_subfolder='/etc' or '/tmp/x' to get/save; deriving the subfolder from an absolute path returned by a file dialog.
Common situations: Storing absolute paths in board metadata; users pasting absolute paths into configuration; code that assumes subfolder can be absolute.
Related errors
- Backslashes not allowed in subfolder path
- Empty path segments not allowed in subfolder path
- Empty path segments not allowed in subfolder path
- No external provider config fields provided
- str(e)
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/cd95714312e2f802.
Report an issue: GitHub.