GHSA-fgv4-6jr3-jgfw: BentoML: Command Injection in cloud deployment setup script
Commit ce53491 (March 24) fixed command injection via `system_packages` in Dockerfile templates and `images.py` by adding `shlex.quote`. However, the cloud deployment path in `src/bentoml/_internal/cloud/deployment.py` was not included in the fix. Line 1648 interpolates `system_packages` directly into a shell command using an f-string without any quoting.The generated script is uploaded to BentoCloud as `setup.sh` and executed on the cloud build infrastructure during deployment, making this a remote code execution on the CI/CD tier.Details**Fixed paths (commit ce53491):**`src/_bentoml_sdk/images.py:88` - added `shlex.quote(package)``src/bentoml/_internal/bento/build_config.py:505` - added `bash_quote` Jinja2 filterJinja2 templates: `base_debian.j2`, `base_alpine.j2`, etc.**Unfixed path:**`src/bentoml/_internal/cloud/deployment.py`, line 1648:`system_packages` values from `bentofile.yaml` are joined with spaces and interpolated directly into the `apt-get install` command. No `shlex.quote`.**Remote execution confirmed:**Line 905: `setup_script = _build_setup_script(bento_dir, svc.image)` in `_init_deployment_files`Line 908: `upload_files.append(("setup.sh", setup_script))` uploads to BentoCloudLine 914: `self.upload_files(upload_files, ...)` sends to the remote deploymentThe script runs on the cloud build infrastructure during container setup**Second caller at line 1068:** `_build_setup_script` is also called during `Deployment.watch()` for dev mode hot-reload deployments.Proof of Conceptbentofile.yaml:Generated setup.sh:The semicolon terminates the `apt-get` command. `${IFS}` is used for spaces (works in bash, avoids YAML parsing issues). The `#` comments out the trailing `|| exit 1`. The injected `curl` exfiltrates the hostname of the build infrastructure to the attacker.ImpactA malicious `bentofile.yaml` achieves remote code execution on BentoCloud's build infrastructure (or enterprise Yatai/Kubernetes build nodes) during deployment. Attack scenarios:**Supply chain:** A shared Bento from a public model hub contains a poisoned `bentofile.yaml`. When deployed to BentoCloud, the injected command runs on the build infrastructure.**Insider threat:** A data scientist with deploy permissions injects commands into `system_packages` to exfiltrate secrets from the build environment (cloud credentials, API keys, other tenants' data).**CI/CD compromise:** The build infrastructure typically has access to container registries, artifact storage, and deployment APIs, making this a pivot point for broader infrastructure compromise.Local Reproduction StepsTested and confirmed on Ubuntu with BentoML source at commit 0772581.Step 1: Create a directory with a malicious bentofile.yaml:Step 2: Generate the setup script using the vulnerable code path (extracted from deployment.py:1648):Step 3: Execute and verify:Result: `/tmp/PWNED_BY_INJECTION` is created, confirming the injected `touch` command executed. The semicolon broke out of `apt-get install`, the injected command ran, and `#` commented out the error handler.Generated setup.sh content:For comparison, the fixed version (with shlex.quote) would generate:The single quotes from shlex.quote neutralize the semicolon and hash, treating the entire string as a literal package name argument to apt-get.Suggested FixApply `shlex.quote` to each package name, matching the fix in `images.py`:— Koda Reef
CVSS v3.1: 7.8