//nefariousplan

CVE-2026-44209: Banks's Template Language Was a Python Interpreter

vendor

patterns

cve

proof of concept

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.

The library is the linguist professor

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:

"Banks is the linguist professor who will help you generate meaningful LLM prompts using a template language that makes sense."

The 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:

from jinja2 import Environment, select_autoescape

env = Environment(
    autoescape=select_autoescape(
        enabled_extensions=("html", "xml"),
        default_for_string=False,
    ),
    trim_blocks=True,
    lstrip_blocks=True,
    enable_async=bool(config.ASYNC_ENABLED),
)

The 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.

The patch is one import line

PR #74, commit dbf7cef, merged 27 April 2026:

-from jinja2 import Environment, select_autoescape
+from jinja2 import select_autoescape
+from jinja2.sandbox import SandboxedEnvironment as Environment

That 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.

The regression test landed in the same commit:

def test_ssti_blocked():
    payload = "{{ self.__init__.__globals__.__builtins__.__import__('os').popen('id').read() }}"
    with pytest.raises(SecurityError):
        Prompt(payload).text()

This 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.

Where the template text comes from

The 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.

banks ships three prompt registries:

  • 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.
  • 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.
  • DirectoryPromptRegistry walks a filesystem tree and reads .jinja and .md files as templates.

None 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:

"Banks provides ways to store prompts on disk along with their metadata. Versioning is a first-class citizen."

A 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().

The 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.

The patch's docs rebrand templates as "trusted code"

The same commit updates docs/prompt.md:

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.

And docs/index.md:

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.

Both 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.

The 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.

F-strings cannot give you RCE

Python'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.

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.

The 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.

This is safe-mode-was-opt-in

The choice between Environment and SandboxedEnvironment is one of the cleanest instances of 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.

The sibling exhibit closest in form is the triple brace in EspoCRM's email template 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.

This is also content-is-command at the prompt-builder layer

The other catalog shape that applies is 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.

The sibling exhibit is bleach is an HTML sanitizer. Jinja2 does not read HTML. 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.

Banks ships the same interpreter without the sanitizer in front, and tells its users the interpreter is a template language.

The widening

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."

The 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.

PoC: advisories/GHSA-gphh-9q3h-jgpp

F-strings remain unable to give you RCE. Banks needed a patch to catch up.