Skip to content

Path Traversal Leading to Arbitrary File Write and Potential Code Execution

High
kovidgoyal published GHSA-32vh-whvh-9fxr Feb 6, 2026

Package

No package listed

Affected versions

< 9.2.0

Patched versions

9.2.0

Description

Summary

Calibre's CHM reader contains a path traversal vulnerability that allows arbitrary file writes anywhere the user has write permissions. On Windows (haven't tested on other OS's), this can lead to Remote Code Execution by writing a payload to the Startup folder, which executes on next login.

Details

Confirmed on: Calibre 9.1.0, Windows 11 (x64)
Trigger: Converting a malicious CHM file via GUI ("Convert books") or CLI (ebook-convert)

Affected Component: src/calibre/ebooks/chm/reader.py

Vulnerable Code (Line 351):

paths.append(path.lstrip('/'))

Only strips leading slash, does not sanitize .. sequences.

Vulnerable Code (Lines 185-198):

for path in self.Contents():
    fpath = path                              # ATTACKER CONTROLLED
    lpath = os.path.join(output_dir, fpath)   # PATH TRAVERSAL
    self._ensure_dir(lpath)                   # Creates dirs OUTSIDE output_dir
    data = self.GetFile(path)
    # ...
    with open(lpath, 'wb') as f:
        f.write(data)                         # ARBITRARY FILE WRITE

Attack Flow:

  1. Malicious CHM contains path: /..\\..\\..\\..\\Roaming\\Microsoft\\Windows\\STARTM~1\\Programs\\Startup\\rce.bat
  2. Contents() returns path with .. intact (only leading / stripped)
  3. os.path.join(output_dir, path) escapes extraction directory
  4. Payload written to Startup folder, executes on next login

PoC:

> python3 create_poc.py
[+] Created: poc.chm
[+] Open poc.chm in Calibre, rce.bat will be written to Startup folder
[+] Tested on Windows 11, Calibre 9.1.0

> dir "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Startup"
rce.bat    78 bytes

# Reboot → calc.exe launches automatically

Proof Files:

  • create_poc.py - Standalone PoC generator

I can't upload the .chm file due to GitHub not supporting it, please feel free to run the create_poc.py.

POC.mp4

create_poc.py

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Local
Attack complexity
Low
Privileges required
None
User interaction
Required
Scope
Changed
Confidentiality
High
Integrity
High
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:H

CVE ID

CVE-2026-25635

Weaknesses

Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')

The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory. Learn more on MITRE.

Credits