You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Path traversal allows reading arbitrary files when converting a text-based file
High
kovidgoyal
published
GHSA-h3p4-m74f-43g6Mar 27, 2026
Package
No package listed
Affected versions
<=9.5
Patched versions
9.6
Description
Summary
A path traversal vulnerability exists in Calibre' handling of images in Markdown and other similar text-based files allowing an attacker to include arbitrary files from the file system into the converted book. Combining this with GHSA-4926-v9px-wv7v allows the files to be exfiltrated to the attacker without additional interaction.
Details
When converting Markdown or other plaintext files into other formats, Calibre first converts them to HTML and then copies any images referred to in the HTML to the output directory. It checks that the resulting path starts with the correct base directory, but does not normalise or sanitize the path. This allows the attacker to include files from outside the base directory via relative path traversal, for example:
<img src="../../../../../../../../etc/passwd">
From ebooks/conversion/plugins/txt_input.py:
deffix_resources(self, html, base_dir):
fromhtml5_parserimportparseroot=parse(html)
changed=Falsebase_dir=os.path.normcase(os.path.abspath(base_dir)) +os.sepforimginroot.xpath('//img[@src]'):
src=img.get('src')
prefix=src.split(':', 1)[0].lower()
ifsrcandprefixnotin ('file', 'http', 'https', 'ftp') andnotos.path.isabs(src):
src=os.path.join(base_dir, src)
# only a startswith check is performed - this does not account for "../"ifos.path.normcase(src).startswith(base_dir) andos.path.isfile(src) andos.access(src, os.R_OK):
withopen(src, 'rb') asf:
data=f.read()
f=self.shift_file(os.path.basename(src), data)
changed=Trueimg.set('src', os.path.basename(f))
ifchanged:
fromlxmlimportetreehtml=etree.tostring(root, encoding='unicode')
returnhtml
This means arbitrary files can be included in the resulting converted ebook.
PoC
Run the attached PoC server with: python3 poc.py
Access the PoC server from a Linux computer with Calibre installed. Any other POSIX system should also work. Note that the path traversal vulnerability does affect Windows also, but the exfiltration via the background-image issue (GHSA-4926-v9px-wv7v) does not.
Download the example Markdown file
Open the file in Calibre ebook reader
Inspect the PoC server output: the /etc/passwd file of the target host should appear there
Alternatively, you can convert the Markdown file to e.g. EPUB and inspect the contents to find the target file (as .passwd). This also works on Windows, as long as you change the target file (EXFIL_FILE) to something that's actually present on Windows.
The product uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize sequences such as .. that can resolve to a location that is outside of that directory.
Learn more on MITRE.
Summary
A path traversal vulnerability exists in Calibre' handling of images in Markdown and other similar text-based files allowing an attacker to include arbitrary files from the file system into the converted book. Combining this with GHSA-4926-v9px-wv7v allows the files to be exfiltrated to the attacker without additional interaction.
Details
When converting Markdown or other plaintext files into other formats, Calibre first converts them to HTML and then copies any images referred to in the HTML to the output directory. It checks that the resulting path starts with the correct base directory, but does not normalise or sanitize the path. This allows the attacker to include files from outside the base directory via relative path traversal, for example:
From
ebooks/conversion/plugins/txt_input.py:This means arbitrary files can be included in the resulting converted ebook.
PoC
python3 poc.py/etc/passwdfile of the target host should appear thereAlternatively, you can convert the Markdown file to e.g. EPUB and inspect the contents to find the target file (as
.passwd). This also works on Windows, as long as you change the target file (EXFIL_FILE) to something that's actually present on Windows.Video:
file-exfiltration-md.mov
poc.py
Impact
The vulnerability allows the attacker to include arbitrary files in the output ebook when the user converts a malicious file.