The vulnerability is a path traversal issue in BentoML, identified as GHSA-6r62-w2q3-48hf. The root cause lies in the bentoml._internal.utils.filesystem.resolve_user_filepath function, which failed to properly sanitize and restrict file paths provided by users in the bentofile.yaml configuration file. This allowed an attacker to craft a malicious bentofile.yaml that, when used in a bentoml build command, could read arbitrary files from the build environment's filesystem.
The vulnerability could be triggered through several fields in bentofile.yaml, including description, docker.setup_script, docker.dockerfile_template, and conda.environment_yml. An attacker could specify paths using traversal sequences (../), absolute paths (/etc/passwd), or even paths to sensitive process information (/proc/self/environ) to exfiltrate data like SSH keys, cloud credentials, and environment variables.
The patch addresses the vulnerability by rewriting the resolve_user_filepath function to include strict security checks. The new implementation introduces a secure mode (enabled by default) which:
- Disallows absolute paths.
- Ensures the resolved file path is within the current working directory (build context).
- Prevents access to hidden files and system directories like
/etc and /proc.
Functions that process the vulnerable fields, such as _build_from_build_config (for the description field) and Image.run_script (for docker.setup_script), were updated to use this new, secure utility function. This comprehensive fix mitigates the path traversal risk across the various attack vectors.