The vulnerability is a command injection in BentoML's Dockerfile generation process. The docker.base_image field in the bento.yaml file is not properly sanitized before being included in the generated Dockerfile. An attacker can provide a multi-line string for docker.base_image that includes malicious Dockerfile RUN commands. When bentoml containerize is executed, these commands are written to the Dockerfile and then executed on the host during the docker build process.
The patch addresses this by introducing a normalize_line Jinja2 filter that strips newlines and collapses whitespace, effectively preventing the injection of additional Dockerfile directives. The functions generate_containerfile in src/bentoml/_internal/container/generate.py and generate_dockerfile in src/_bentoml_impl/docker.py are the key functions involved in this vulnerable process. They are responsible for taking the user-provided configuration and generating the Dockerfile. The patch modifies these functions and the templates they use to ensure the base_image is properly sanitized.