{"record":{"id":"a42dcc5a6c2eb688","repo":"langchain-ai/deepagents","slug":"media-path-must-not-contain-parent-directory-trave","errorCode":null,"errorMessage":"media path must not contain parent-directory traversal: {path}","messagePattern":"media path must not contain parent-directory traversal: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/talon/deepagents_talon/media.py","lineNumber":223,"sourceCode":"    Raises:\n        ValueError: If the path is unsafe, unavailable, or escapes `root`.\n    \"\"\"\n    raw = str(path)\n    parsed = urlparse(raw)\n    windows_path = PureWindowsPath(raw)\n    is_windows_drive_path = bool(windows_path.drive)\n    if parsed.scheme and not is_windows_drive_path:\n        msg = f\"media path must be a local filesystem path: {path}\"\n        raise ValueError(msg)\n    if raw.startswith(\"~\") or (\n        require_relative\n        and (path.is_absolute() or windows_path.is_absolute() or is_windows_drive_path)\n    ):\n        msg = f\"media path must be a local relative path under the outbound root: {path}\"\n        raise ValueError(msg)\n    if \"..\" in path.parts or \"..\" in windows_path.parts:\n        msg = f\"media path must not contain parent-directory traversal: {path}\"\n        raise ValueError(msg)\n\n    root_resolved = root.expanduser().resolve()\n    candidate_input = root_resolved / path if not path.is_absolute() else path\n    try:\n        candidate = candidate_input.resolve(strict=True)\n    except OSError as exc:\n        msg = f\"media file is unavailable: {path}\"\n        raise ValueError(msg) from exc\n    if not candidate.is_relative_to(root_resolved):\n        msg = f\"media path escapes outbound root: {path}\"\n        raise ValueError(msg)\n    if not candidate.is_file():\n        msg = f\"media path is not a regular file: {path}\"\n        raise ValueError(msg)\n    return candidate\n\n\ndef _document_parts(paths: list[Path]) -> list[str]:","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/talon/deepagents_talon/media.py#L205-L241","documentation":"ValueError raised by resolve_bounded_media_path when the path contains '..' components (checked in both POSIX and Windows parsing). Parent-directory traversal is blocked to prevent paths escaping the outbound root.","triggerScenarios":"Passing 'images/../../etc/passwd' or '..\\\\..\\\\secret.png' as media path.","commonSituations":"User-supplied filenames joined without sanitization; constructing paths with string concatenation that introduces '..'; path templates from untrusted input.","solutions":["Remove '..' components and pass a clean relative path under the outbound root","Normalize user input with a sanitizer or reject names containing path separators/'..' before joining","Use pathlib to join (root / name) with a validated bare filename"],"exampleFix":"// before\nresolve_bounded_media_path(Path(f\"uploads/{user_input}\"), root)  # user_input=\"../x.png\"\n// after\nname = Path(user_input).name  # strips directories/traversal\nresolve_bounded_media_path(Path(\"uploads\") / name, root)","handlingStrategy":"validation","validationCode":"relative = Path(user_input)\nif \"..\" in relative.parts or \"..\" in PureWindowsPath(user_input).parts:\n    raise ValueError(f\"traversal rejected: {user_input}\")","typeGuard":"def is_safe_relative(p: Path) -> bool:\n    return \"..\" not in p.parts and not p.is_absolute()","tryCatchPattern":"try:\n    resolved = resolve_bounded_media_path(path, root)\nexcept ValueError as exc:\n    logger.warning(\"Rejected media path: %s\", exc)\n    return None","preventionTips":["Sanitize user-supplied filenames with Path(name).name before joining","Reject any input containing '..' or path separators at your API boundary","Join with pathlib (root / name), never string concatenation"],"tags":["media","path","security","traversal"],"backgroundTag":"path-traversal","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}