Summary
A path traversal flaw in Calibre's CHM reader allows crafted content to write files to arbitrary locations where the current user has write permissions.
On Windows, this can be chained to remote code execution by placing attacker-controlled files in the user's Startup folder, causing them to run on the next login.
Affected context
The vulnerability affects environments where Calibre is used to open CHM (Compiled HTML Help) files with the built-in CHM reader.
It becomes relevant when Calibre processes paths embedded in CHM content or related resources without proper normalization or restriction to a safe base directory.
The issue is particularly dangerous on Windows systems, where writing files into special user-controlled locations (such as Startup folders) can result in code execution during normal system use.
Exploit preconditions
- Attack surface: Opening or processing attacker-supplied CHM files or CHM-derived content in Calibre's CHM reader.
- Required access: Ability to convince a user to open a malicious CHM file in Calibre, or otherwise supply untrusted CHM content to the reader.
- Trigger point: Calibre's CHM processing logic handling file paths and writing extracted or generated files to disk.
- Why exploitation is possible: The CHM reader does not sufficiently validate or normalize file paths, allowing directory traversal sequences to escape the intended directory and target arbitrary writable locations.
Why this happens
This vulnerability stems from improper restriction of file paths when writing files derived from CHM content.
User-controllable path components from inside the CHM file are used to construct filesystem paths without robust normalization and enforcement of a safe root directory.
As described by CWE-22: Improper Limitation of a Pathname to a Restricted Directory, directory traversal sequences (such as ../) or absolute paths are allowed to influence the destination, enabling writes outside the intended sandbox.
The insecure pattern is treating paths from a semi-trusted archive format (CHM) as safe for direct use with filesystem APIs.
Potential impact
- Arbitrary file creation or overwrite in any directory where the user has write permissions
- Placement of malicious executables or scripts in the Windows Startup folder leading to code execution on next login
- Persistence of attacker-controlled code under the user account
- Overwriting configuration or data files to corrupt application behavior or cause data loss
- Facilitating further compromise by planting helper tools or backdoors in trusted locations
General mitigation guidance
Mitigation generally focuses on hardening file handling and constraining where data from CHM content can be written:
- Normalize and canonicalize all paths derived from CHM content before use, resolving
.and..segments and symbolic links where relevant. - Enforce a strict base directory for CHM extraction or writes and reject any path that attempts to escape this directory after normalization.
- Treat archive-internal paths as untrusted input: strip absolute paths, drive letters, and special folders, and map them to safe, application-controlled names.
- Implement allowlists for output locations and file types when extracting or generating files from CHM data.
- Run the application with the minimum necessary filesystem privileges and avoid writing to sensitive or executable search paths by default.
How teams detect issues like this
Detection strategies can combine code-centric review with behavioral monitoring:
- Static analysis: Search for file write operations where the destination path is influenced by CHM file contents or other untrusted inputs without normalization and base-directory checks.
- Code review: Flag any path construction logic in the CHM reader that concatenates user-controlled strings to filesystem paths, especially where
.., absolute paths, or environment-dependent directories might be honored. - Unit and security testing: Add tests that attempt to write via traversal sequences (e.g.,
../) or to platform-specific sensitive directories and validate that these are rejected. - Runtime monitoring: On endpoints, monitor the application for unexpected writes into Startup folders or other auto-execution locations, which may indicate exploitation attempts.

