-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The vulnerable code is twelve lines\n\nCVE-2026-44181 is `enterprise_gateway/services/processproxies/k8s.py`, at the parent commit of the August 8, 2025 fix:\n\n```python\ndef _determine_kernel_pod_name(self, **kwargs: dict[str, Any] | None) -> str:\n pod_name = kwargs[\"env\"].get(\"KERNEL_POD_NAME\")\n if pod_name is None:\n pod_name = KernelSessionManager.get_kernel_username(**kwargs) + \"-\" + self.kernel_id\n else:\n self.log.debug(f\"Processing KERNEL_POD_NAME based on env var => {pod_name}\")\n if \"{{\" in pod_name and \"}}\" in pod_name:\n self.log.debug(\"Processing KERNEL_POD_NAME as jinja template\")\n # Create Jinja2 environment\n keywords = {}\n for name, value in kwargs[\"env\"].items():\n if name.startswith(\"KERNEL_\"):\n keywords[name.lower()] = value\n keywords[\"kernel_id\"] = self.kernel_id\n self.log.debug(\"Processing pod_name jinja template\")\n env = Environment(loader=BaseLoader(), autoescape=True)\n pod_name = env.from_string(pod_name).render(**keywords)\n```\n\n`pod_name` on line one is the value the client sent for the `KERNEL_POD_NAME` environment variable. The variable arrives through Enterprise Gateway's REST API, which accepts a JSON `env` dictionary on every kernel-start request and copies every `KERNEL_*` prefixed entry into the kernel-launch environment. Three nested conditions later, that value is the first argument to `env.from_string(...)`. In Jinja2's API, the argument to `from_string` is the template source. The remaining call, `.render(**keywords)`, evaluates the template against a namespace.\n\nA request body of `{\"env\": {\"KERNEL_POD_NAME\": \"bdawg-{{7*7}}\"}}` produces a pod named `bdawg-49`. A request body of:\n\n```json\n{\"env\": {\"KERNEL_POD_NAME\": \"bdawg-{{cycler.__init__.__globals__.os.popen('hostname').read()}}\"}}\n```\n\nrenders by reaching for the `cycler` builtin Jinja2 exposes in its runtime namespace, walking through its `__init__` method's `__globals__` to find the `os` module imported in `jinja2.utils`, calling `os.popen('hostname').read()`, and interpolating the result into the rendered string. The rendered string becomes the pod name. The string is also the proof of execution; the attacker's command ran inside the Enterprise Gateway process, before any pod existed, with the gateway's service-account token reachable on the local filesystem at `/var/run/secrets/kubernetes.io/serviceaccount/token`. That token is what the GHSA advisory is describing when it warns that the bug \"enables an attacker to steal the gateway's Kubernetes service account token.\"\n\nThe `autoescape=True` argument to `Environment` is what makes the choice interesting. Jinja2's `autoescape` is an HTML-encoding pass applied to expression output before that output is inserted into the rendered string. It does not constrain which expressions evaluate. It does not restrict which builtins the template can reference. It does not stop `cycler.__init__.__globals__.os.popen` from resolving. `jinja2.sandbox.SandboxedEnvironment` does that. The pre-patch code imports `Environment` from `jinja2`, not `SandboxedEnvironment`, and passes the attacker's bytes to `from_string` directly.\n\nThe flag belongs in the codebase. On the manifest-rendering path elsewhere in the project, where the template source is the checked-in `kernel-pod.yaml.j2` file and the variables are filled from server state, `autoescape` does useful work encoding `<` as `<` inside YAML scalar values. The path that takes a client-supplied string and runs `from_string` on it is a different path, and `autoescape` has nothing to say there.\n\n## The fix understands the threat\n\n```python\ndef _safe_template_substitute(self, template_str: str, variables: dict) -> str | None:\n \"\"\"\n Safely substitute variables in Jinja2-style template syntax.\n Only supports simple variable substitution: {{ variable_name }}\n Logs missing variables and returns None if any are missing.\n \"\"\"\n # Pattern to match {{ variable_name }} with optional whitespace\n # Explicitly exclude variables starting with underscore to prevent magic method attacks\n pattern = r'\\{\\{\\s*([a-zA-Z][a-zA-Z0-9_]*)\\s*\\}\\}'\n missing_vars = []\n\n def replace_var(match):\n var_name = match.group(1)\n if var_name in variables:\n return str(variables[var_name])\n else:\n missing_vars.append(var_name)\n return match.group(0)\n\n result = re.sub(pattern, replace_var, template_str)\n\n if '{{' in result and '}}' in result:\n self.log.warning(\n \"Invalid template syntax detected in KERNEL_POD_NAME: contains unsupported expressions\"\n )\n return None\n ...\n```\n\nThe replacement matches `{{ variable_name }}` with an identifier-only character class. The character class begins at `[a-zA-Z]`, not `[_a-zA-Z]`. The comment names \"magic method attacks.\" A second sweep at the end of the function rejects any input that still contains both `{{` and `}}` after substitution, which catches anything the identifier-only regex did not match. The function returns `None` when it fails, and the caller falls back to the default pod name.\n\nThe PR shipped 231 lines of new tests. One test is named `test_malicious_template_injection_prevention`. Its payload list includes `''.__class__.__mro__[1].__subclasses__()[104].__init__.__globals__['sys'].exit()`, `{{ kernel_id.__class__ }}`, and `{{ kernel_id.__globals__ }}`. The author of the PR knew what a Python SSTI looks like in 2025. The author of the PR is the same account that introduced the Jinja2 environment in 2024, the same account that authored the YAML-injection fix in 2026, and the same account credited as `lresende` on the GHSA advisory's remediation byline. The maintainer's commit message on August 8, 2025 was `Fix KERNEL_POD_NAME substitution to avoid SSTI`. The release that made that commit installable through pip was tagged on June 1, 2026.\n\n## v3.2.3 to v3.3.0 was 833 days\n\n`git log v3.2.3..v3.3.0 -- enterprise_gateway/services/processproxies/k8s.py`:\n\n```\n571c992 2025-08-17 change V1Subject to RbacV1Subject in k8s.py (#1384)\n1e6b2f3 2025-08-08 Fix KERNEL_POD_NAME substitution to avoid SSTI (#1412)\n```\n\nTwo commits. The first is a Kubernetes API name change. The second is the SSTI fix. Between the v3.2.3 tag on February 19, 2024 and the v3.3.0 tag on June 1, 2026, no version of this file shipped to a release tag other than what was in v3.2.3. The release pipeline was idle. The trunk was not.\n\nThe introduction of the Jinja2 environment for `KERNEL_POD_NAME` was commit `dd9e4ba` in PR #1368, authored by the same maintainer, with timestamp `2024-02-19 16:16:21 -0800`. The v3.2.3 tag, commit `7c3c598`, has timestamp `2024-02-19 21:03:27 -0800`. Four hours and forty-seven minutes between the bug landing and the bug shipping to pip. The release notes for v3.2.3 list the PR by its title, \"Add jinja template support to pod-name config via environment variable.\"\n\nThe release pipeline being idle for 833 days is not unusual for a project at maintenance velocity. Jupyter Enterprise Gateway has one primary maintainer; releases get cut when the maintainer cuts them. The unusual choice is to land a security fix during that window and not cut a patch release for the fix. The commit message is a public statement that the prior released version was vulnerable. Anyone reading the maintainer's commits had a roadmap.\n\nThe GHSA advisory credits `ben-elttam` as the reporter. `elttam` is an Australian security consultancy. Two readings of the timeline are available. The first is that ben-elttam reported the bug to the maintainer in mid-2025, the maintainer fixed it in August 2025, and the project sat on releasing the fix for nearly ten months. The second is that ben-elttam found the bug by reading the maintainer's August 2025 commit log, filed an advisory against the still-vulnerable release on pip, and the project cut v3.3.0 in response. The advisory's publication date is two days after v3.3.0 shipped. Neither reading lets the release pipeline off. This is release-lag-disclosure in its canonical shape: the fix was a published source artifact for nine-and-a-half months while the package manager kept serving the unpatched binary.\n\n## The substrate is one Jinja2 environment\n\nv3.3.0 also fixed [GHSA-cfw7-6c5v-2wjq](https://github.com/jupyter-server/enterprise_gateway/security/advisories/GHSA-cfw7-6c5v-2wjq), the YAML structure-injection bug that lets `KERNEL_*` environment variables decode YAML escape sequences inside the Kubernetes manifest template and inject new resource declarations into the rendered output. That fix landed eight months after the SSTI fix, in commit `2258a41` on April 27, 2026. Same author. Same `KERNEL_*`-into-Jinja2 surface. Different exploit shape: the SSTI ran `env.from_string(value).render(...)` on the client string in `k8s.py`; the YAML injection ran `yaml.safe_load(value)` on the client string in `launch_kubernetes.py`, fed the parsed structure into a Jinja2 template that renders into YAML, and let `yaml.safe_load_all` re-parse the result. The patch for the second bug introduces a `yaml_safe` Jinja2 filter and adds post-render validation that the rendered manifest contains only expected resource kinds. The patch's commit message names the substrate without using the word: \"Attacker-controlled KERNEL_* environment variables were interpolated into Kubernetes manifests via Jinja2 templates.\"\n\nThis is [design-debt-driver](/patterns/design-debt-driver) in compact form. The substrate is the Enterprise Gateway feature that walks `os.environ` for `KERNEL_*` prefixed values and feeds them, individually or in batch, into Jinja2 templates that render Kubernetes manifests. The introduction of `KERNEL_POD_NAME` Jinja2 expansion is dated February 2024. The introduction of the YAML round-trip is older, present in `launch_kubernetes.py` since the initial Kubernetes process proxy. Two consecutive CVEs against the same substrate were patched in the same release. The catalog's [Apache Camel CVE-2026-40858](/posts/camel-cve-2026-40858-same-five-lines-eight-components) exhibit is the same shape one component layer up: one substrate, eight separate CVEs, one maintainer cleaning up one component at a time. Enterprise Gateway's substrate produced two and is patched at the substrate level for two specific sinks. The next CVE on this surface, if there is one, will be a third call site reading `KERNEL_*` env values into a sink with a different parser.\n\n## The CVE caught up to the release, not to the fix\n\nCVE-2026-44181 is dated June 3, 2026. The fix commit is dated August 8, 2025. The user-installable release containing the fix is dated June 1, 2026. The advisory's \"patched in 3.3.0\" field is correct and complete. The advisory's \"affected versions\" field, `>= 2.0.0rc2, < 3.3.0`, is also correct and complete; the last release tag in that range is `v3.2.3`, the release that shipped the unfixed code on February 19, 2024.\n\nThe version on pip on November 1, 2025, three months after the SSTI fix was committed to `main` and titled \"to avoid SSTI\" in the public git log, was `v3.2.3`. The version on pip on February 8, 2026, six months after the fix, was `v3.2.3`. The version on pip on May 31, 2026, the day before v3.3.0 was tagged, was `v3.2.3`. On each of those days, an operator running `pip install --upgrade jupyter_enterprise_gateway` against PyPI got the SSTI.\n\nPoC: [github.com/advisories/GHSA-f49j-v924-fx9w](https://github.com/advisories/GHSA-f49j-v924-fx9w).","closing_line":"The SSTI fix was a public commit. The CVE was a published release. They are not the same event.","hook_md":"On August 8, 2025, the maintainer of Jupyter Enterprise Gateway pushed a commit to `main` titled \"Fix KERNEL_POD_NAME substitution to avoid SSTI (#1412).\" The PR's diff removes a call to `jinja2.Environment.from_string()` on an attacker-controlled string. The PR's 231-line test file is named `test_process_proxy.py` and includes a test called `test_malicious_template_injection_prevention` whose inputs are `''.__class__.__mro__[1].__subclasses__()[104].__init__.__globals__['sys'].exit()` and `{{ kernel_id.__class__ }}`. The commit is public on GitHub.\n\nThe first release tag containing that commit was cut 297 days later, on June 1, 2026. CVE-2026-44181 was assigned to the bug two days after that.","post_id":552,"slug":"jupyter-enterprise-gateway-cve-2026-44181-fix-public-before-release","title":"CVE-2026-44181: Jupyter Enterprise Gateway Fixed The SSTI In Trunk. The Release Carrying The Fix Shipped 297 Days Later.","type":"initial","unreadable_sentence":"The SSTI fix was a public commit. The CVE was a published release. They are not the same event."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCaqWa0AAKCRDeZjl4jgkQ JmdFAQC5clUOonYGev7Bc/kqLS0y0e7dWWjLrw0iRtWEMWeoqwEAkx6l84Be2GIn vwZeTYvhg0/yAtqBIO+MDRCuZqMoSQM= =hMna -----END PGP SIGNATURE-----