-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The library is the linguist professor\n\n`banks` is a Python prompt-template library for LLMs. The name comes from Louise Banks, the linguist in *Arrival*. The README's first paragraph extends the metaphor:\n\n> \"Banks is the linguist professor who will help you generate meaningful LLM prompts using a template language that makes sense.\"\n\nThe pitch is consistent across the project's documentation. Prompts need structure. Concatenation is not structure. The right tool is a real template language. The real template language is Jinja2. From `src/banks/env.py`, pre-patch:\n\n```python\nfrom jinja2 import Environment, select_autoescape\n\nenv = Environment(\n autoescape=select_autoescape(\n enabled_extensions=(\"html\", \"xml\"),\n default_for_string=False,\n ),\n trim_blocks=True,\n lstrip_blocks=True,\n enable_async=bool(config.ASYNC_ENABLED),\n)\n```\n\nThe import is the bug. `jinja2.Environment` is not a template engine in the sense banks's README implies. It is a Python expression evaluator with template-shaped syntax around it. Jinja2 ships a second class for the case where templates carry content the caller does not author: `jinja2.sandbox.SandboxedEnvironment`. The two classes are interchangeable at the construction call site. They differ in one thing. The sandboxed one blocks attribute access to dunder methods on objects reachable from the template namespace. The unsandboxed one does not.\n\n## The patch is one import line\n\nPR #74, commit `dbf7cef`, merged 27 April 2026:\n\n```diff\n-from jinja2 import Environment, select_autoescape\n+from jinja2 import select_autoescape\n+from jinja2.sandbox import SandboxedEnvironment as Environment\n```\n\nThat is the entire code change. The `Environment(...)` construction block immediately below is untouched. The fix is to rename the import so the same identifier resolves to a different class.\n\nThe regression test landed in the same commit:\n\n```python\ndef test_ssti_blocked():\n payload = \"{{ self.__init__.__globals__.__builtins__.__import__('os').popen('id').read() }}\"\n with pytest.raises(SecurityError):\n Prompt(payload).text()\n```\n\nThis is the canonical Python SSTI payload. Pre-patch, `Prompt(payload).text()` ran `id` in the host process and returned the output as the rendered template. Post-patch, Jinja2's sandbox raises `SecurityError` at the first `__init__` lookup. The render path is the same. The class doing the rendering is the line that changed.\n\n## Where the template text comes from\n\nThe vendor advisory frames CVE-2026-44209 around \"applications that pass user-supplied strings as the template argument to `Prompt()`.\" That framing places the bug at the immediate caller. The library's own architecture makes the framing harder to maintain than it sounds.\n\n`banks` ships three prompt registries:\n\n- `RedisPromptRegistry.get(name=...)` reads a JSON-serialized `PromptModel` from Redis and constructs `Prompt(**prompt_data)`. The template text is whatever bytes the Redis key holds.\n- `FilePromptRegistry.get(name=...)` reads a JSON-serialized `PromptModel` from disk and constructs `Prompt(**prompt_data)`. The template text is whatever bytes the JSON file holds.\n- `DirectoryPromptRegistry` walks a filesystem tree and reads `.jinja` and `.md` files as templates.\n\nNone of these registries treat the template text as user-controlled. None of them mention SSTI. None of them validated the template against any grammar before the patch. The library's positioning is that templates are an artifact you store in infrastructure:\n\n> \"Banks provides ways to store prompts on disk along with their metadata. Versioning is a first-class citizen.\"\n\nA versioned, registry-backed, infrastructure-managed artifact is not a constant in your source code. It is whatever the registry returns on the next read. Anyone who can write to the registry has written code that the prompt builder will execute on the next call to `Prompt(**prompt_data).text()`.\n\nThe vendor's framing is correct in a narrow sense. The immediate caller of `Prompt(user_input)` is the application. The framing is wrong in the practical sense that every feature the library sells (registries, versioning, metadata, the Redis backend) moves the template text into a mutable store. The library was selling prompt templates as data. The library was treating them as code.\n\n## The patch's docs rebrand templates as \"trusted code\"\n\nThe same commit updates `docs/prompt.md`:\n\n> **Templates are trusted code.** Banks renders templates using Jinja2's `SandboxedEnvironment`. This helps mitigate SSTI risk, but it should not be treated as a hard security boundary. Never construct a `Prompt` from user-supplied strings.\n\nAnd `docs/index.md`:\n\n> Banks uses Jinja2 to render prompt templates through a sandboxed environment to help reduce server-side template injection (SSTI) risk. However, do not pass untrusted user input as template text. User-controlled templates are still unsafe, and the sandbox is not a guaranteed security boundary.\n\nBoth passages say two things at once. The first is \"we added the sandbox.\" The second is \"the sandbox does not bound the threat.\" Jinja2's documentation has always been clear on that hedge. `SandboxedEnvironment` blocks dunder access. It does not block every path to Python state. Filters can be invoked. Callable attributes can be reached. Registered extensions (Banks adds `ChatExtension` and `CompletionExtension`) run inside the sandbox with their own privileges. The library is repeating Jinja2's existing hedge directly to its users.\n\nThe interesting phrase in the new docs is \"trusted code.\" The README's pitch was a \"template language that makes sense.\" Three years after the initial release, the docs reclassify the same artifact as \"trusted code.\" A template language is something you write content in. Trusted code is something you write programs in. The patch shipped the rebrand and the sandbox in one commit.\n\n## F-strings cannot give you RCE\n\nPython's f-strings are syntactic sugar over `str.__format__` with expression evaluation that runs once, in the calling scope, at format time. The expressions are author-written code in the source file. The values substituted into the result are concatenated as bytes. An f-string `f\"Write a blog about {topic}\"` with `topic = \"__import__('os').popen('id').read()\"` produces the literal string `Write a blog about __import__('os').popen('id').read()`. The string is dangerous to feed to an LLM, in the LLM-prompt-injection sense. It is not dangerous to render. It does not execute Python on the host.\n\n`banks.Prompt(\"Write a blog about {{ topic }}.\").text({\"topic\": user_input})` produces the same literal string for the same input. The variable-substitution path is safe; Jinja2 treats variable values as data. The unsafe path is `banks.Prompt(user_input).text()`. The bytes in the template, not the bytes in the variables, are what Jinja2 compiles.\n\nThe library introduced a new class of bug f-strings cannot have. F-strings substitute. Jinja2's `Environment` evaluates. The library that wrapped Jinja2 told its users it was wrapping an f-string. The wrapping was unidirectional. Interpreters can be told to act like interpolators. Interpolators cannot become interpreters.\n\n## This is safe-mode-was-opt-in\n\nThe choice between `Environment` and `SandboxedEnvironment` is one of the cleanest instances of [safe-mode-was-opt-in](/patterns/safe-mode-was-opt-in) the catalog carries. Jinja2 exposes both. The unsafe one lives at the top of the package namespace, reachable as `from jinja2 import Environment`. The safe one requires reaching into a submodule, `from jinja2.sandbox import SandboxedEnvironment`. The catalog has six previous exhibits of the same shape, defaults doing the work in libraries whose downstream callers reached for the most natural-looking import.\n\nThe sibling exhibit closest in form is [the triple brace in EspoCRM's email template was correct](/posts/espocrm-cve-2026-33657-triple-brace-was-correct). EspoCRM called Michelf Markdown's `defaultTransform` ignoring `no_markup` and `no_entities`. The flags existed on the class. The factory helper did not set them. The 9.3.4 fix wrapped the parser with both flags on. Banks's fix is structurally identical at slightly coarser grain. One factory name (`Environment`) is replaced by another (`SandboxedEnvironment as Environment`). The safer class exists in Jinja2. The fix is to reach for it.\n\n## This is also content-is-command at the prompt-builder layer\n\nThe other catalog shape that applies is [content-is-command](/patterns/content-is-command). The library's job is to take prompt content and feed it to an interpreter. The pattern's mechanism: an input channel the system treated as passive data turns out to be the same channel it reads instructions from. Banks is the same shape, applied a layer below the LLM.\n\nThe sibling exhibit is [bleach is an HTML sanitizer. Jinja2 does not read HTML.](/posts/tandoor-recipes-bleach-is-not-a-jinja-sandbox) Tandoor Recipes stored user input in a database column, ran `bleach` over it as a sanitizer, and rendered the result through Jinja2. The bleach output is HTML. Jinja2's input is Python expressions. The sanitizer and the interpreter were not aligned. Tandoor's fix removed Jinja2 from that path.\n\nBanks ships the same interpreter without the sanitizer in front, and tells its users the interpreter is a template language.\n\n## The widening\n\n`banks` is one library. The shape generalises. Every LLM application that loads prompt templates from a registry has the same surface. The libraries built around the assumption that prompts are versioned artifacts encourage exactly this: prompts on disk, prompts in Redis, prompts behind a prompt-management UI. There is no convention in the LLM-tooling space that says \"the contents of your prompt registry are arbitrary Python.\" There is no review process in the prompt-engineering literature that says \"your prompt versioning system needs the same gate as your CI/CD pipeline.\"\n\nThe vendor advisory says \"do not pass user-supplied strings as the template argument.\" That names the immediate caller. The library's documentation sells the registry as the right place to put templates. The registry is not the immediate caller. Whoever has write access to the registry has code execution against the prompt-rendering process.\n\nPoC: [advisories/GHSA-gphh-9q3h-jgpp](https://github.com/advisories/GHSA-gphh-9q3h-jgpp)","closing_line":"F-strings remain unable to give you RCE. Banks needed a patch to catch up.","hook_md":"Banks's README opens with: \"If you're still using f-strings for the job, keep reading.\" The job is building LLM prompts. The pitch is that f-strings are too primitive and that you should use a template engine instead. CVE-2026-44209 is the one-line patch that switches the project's template engine from Jinja2's default `Environment` to `jinja2.sandbox.SandboxedEnvironment`, three years after the project's first commit. F-strings cannot give you RCE. Banks could.","post_id":507,"slug":"banks-cve-2026-44209-template-language-was-a-python-interpreter","title":"CVE-2026-44209: Banks's Template Language Was a Python Interpreter","type":"initial","unreadable_sentence":"F-strings cannot give you RCE. Banks could."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCaoM+ZgAKCRDeZjl4jgkQ JrGTAQCXvXtKytC780pGxzeM7gTDTBu3SOuoYCubSsDQLJKWHwEAuxkYDPlb394e mHLO842filAM/gAWWwsGUL+ImpfFiQw= =S/rJ -----END PGP SIGNATURE-----