Spaces:
Sleeping
Sleeping
Download debug_env/server/utils/validation.py from VanshGoel1/debug-env: direct link, hf CLI and curl.
- Browser
- Download file 846 Bytes
-
https://huggingface.co/spaces/VanshGoel1/debug-env/resolve/main/debug_env/server/utils/validation.py
- Command line
-
hf download hf://spaces/VanshGoel1/debug-env/debug_env/server/utils/validation.py
-
curl -L -o validation.py https://huggingface.co/spaces/VanshGoel1/debug-env/resolve/main/debug_env/server/utils/validation.py
846 Bytes
| """ | |
| Common validation utilities shared across tool handlers. | |
| """ | |
| import os | |
| def validate_workdir_path(workdir: str, path: str) -> str: | |
| """ | |
| Resolve *path* against *workdir* and verify it stays inside the workdir. | |
| Args: | |
| workdir: Absolute path to the task working directory. | |
| path: Relative filename from the agent (e.g. ``"broken_code.py"``). | |
| Returns: | |
| The resolved absolute path. | |
| Raises: | |
| ValueError: If the resolved path escapes the workdir boundary. | |
| """ | |
| resolved = os.path.realpath(os.path.join(workdir, path)) | |
| workdir_real = os.path.realpath(workdir) | |
| if not resolved.startswith(workdir_real + os.sep) and resolved != workdir_real: | |
| raise ValueError( | |
| f"Path '{path}' resolves outside the task workdir — access denied." | |
| ) | |
| return resolved | |