PaddlePaddle/PaddleOCR · error · InvalidRequestError
Unsafe resource filename: {name}
Error message
Unsafe resource filename: {name} What it means
Raised when a result-resource filename fails the safety check in _validate_result_resource_filename: the name must equal Path(name).name and contain no '/' or '\\' and not be '.' or '..'. This is a path-traversal guard for files downloaded/derived from API result URLs. Note the internal caller neutralizes this error (returns '' on InvalidRequestError), so seeing it requires direct validator use or a URL whose suffix embeds separators.
Source
Thrown at paddleocr/_api_client/_resources.py:212
def _safe_resource_extension(resource_url: str) -> str:
parsed = urlparse(resource_url)
suffix = Path(unquote(parsed.path)).suffix
if not suffix:
return ""
try:
_validate_result_resource_filename(f"resource{suffix}")
except InvalidRequestError:
return ""
return suffix
def _validate_result_resource_filename(name: str) -> None:
if not name:
raise InvalidRequestError("Resource filename must not be empty.")
path = Path(name)
if path.name != name or "/" in name or "\\" in name or name in (".", ".."):
raise InvalidRequestError(f"Unsafe resource filename: {name}")
View on GitHub (pinned to 2661c7c0ef)
Solutions
- Sanitize with Path(name).name before validation
- Reject or skip resources whose names contain path separators instead of passing them through
Example fix
// before
_validate_result_resource_filename(user_provided_name)
// after
from pathlib import Path
safe = Path(user_provided_name).name
if safe in ('', '.', '..'):
raise ValueError('bad resource name')
_validate_result_resource_filename(safe) Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
def is_safe_resource_name(name: str) -> bool:
return bool(name) and Path(name).name == name and '/' not in name and '\\' not in name and name not in ('.', '..') Try / catch
from paddleocr._api_client.errors import InvalidRequestError
try:
_validate_result_resource_filename(name)
except InvalidRequestError as e:
raise ValueError(f'rejected resource name {name!r}') from e Prevention
- Always reduce to Path(name).name before using API-derived filenames
- Never join untrusted names into output paths without sanitization
When it happens
Trigger: Calling _validate_result_resource_filename('a/b.txt'), ('..'), ('dir\\file'), or any name where Path(name).name != name.
Common situations: Direct use of the private validator during custom result handling; crafting filenames from untrusted API responses without sanitization.
Related errors
- fileUrl and filePath are mutually exclusive.
- File not found: ${path}
- Bad request: ${text}
- OCR pipeline config text must decode to an object.
- OCR pipeline config must be an object or YAML text.
AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14).
Data as JSON: /api/errors/423abd7d63574fa2.
Report an issue: GitHub.