{"record":{"id":"423abd7d63574fa2","repo":"PaddlePaddle/PaddleOCR","slug":"unsafe-resource-filename-name","errorCode":null,"errorMessage":"Unsafe resource filename: {name}","messagePattern":"Unsafe resource filename: (.+?)","errorType":"validation","errorClass":"InvalidRequestError","httpStatus":null,"severity":"error","filePath":"paddleocr/_api_client/_resources.py","lineNumber":212,"sourceCode":"\ndef _safe_resource_extension(resource_url: str) -> str:\n    parsed = urlparse(resource_url)\n    suffix = Path(unquote(parsed.path)).suffix\n    if not suffix:\n        return \"\"\n    try:\n        _validate_result_resource_filename(f\"resource{suffix}\")\n    except InvalidRequestError:\n        return \"\"\n    return suffix\n\n\ndef _validate_result_resource_filename(name: str) -> None:\n    if not name:\n        raise InvalidRequestError(\"Resource filename must not be empty.\")\n    path = Path(name)\n    if path.name != name or \"/\" in name or \"\\\\\" in name or name in (\".\", \"..\"):\n        raise InvalidRequestError(f\"Unsafe resource filename: {name}\")\n","sourceCodeStart":194,"sourceCodeEnd":213,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/paddleocr/_api_client/_resources.py#L194-L213","documentation":"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.","triggerScenarios":"Calling _validate_result_resource_filename('a/b.txt'), ('..'), ('dir\\\\file'), or any name where Path(name).name != name.","commonSituations":"Direct use of the private validator during custom result handling; crafting filenames from untrusted API responses without sanitization.","solutions":["Sanitize with Path(name).name before validation","Reject or skip resources whose names contain path separators instead of passing them through"],"exampleFix":"// before\n_validate_result_resource_filename(user_provided_name)\n// after\nfrom pathlib import Path\nsafe = Path(user_provided_name).name\nif safe in ('', '.', '..'):\n    raise ValueError('bad resource name')\n_validate_result_resource_filename(safe)","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\ndef is_safe_resource_name(name: str) -> bool:\n    return bool(name) and Path(name).name == name and '/' not in name and '\\\\' not in name and name not in ('.', '..')","typeGuard":null,"tryCatchPattern":"from paddleocr._api_client.errors import InvalidRequestError\n\ntry:\n    _validate_result_resource_filename(name)\nexcept InvalidRequestError as e:\n    raise ValueError(f'rejected resource name {name!r}') from e","preventionTips":["Always reduce to Path(name).name before using API-derived filenames","Never join untrusted names into output paths without sanitization"],"tags":["security","path-traversal","validation"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}