Skip to content

🔒 Fix CVE-2025-26240: Secure HTML Meta Tag Option Parsing#276

Open
AdnanMuhib wants to merge 8 commits into
JazzCore:masterfrom
AdnanMuhib:fix_CVE_2025_26240
Open

🔒 Fix CVE-2025-26240: Secure HTML Meta Tag Option Parsing#276
AdnanMuhib wants to merge 8 commits into
JazzCore:masterfrom
AdnanMuhib:fix_CVE_2025_26240

Conversation

@AdnanMuhib

Copy link
Copy Markdown

🔒 Fix CVE-2025-26240: Secure HTML Meta Tag Option Parsing

📝 Summary

This PR addresses the security vulnerability CVE-2025-26240 (#267) in python-pdfkit. Previously, parsing HTML meta tags with the pdfkit- prefix allowed the injection of arbitrary wkhtmltopdf options (such as --enable-local-file-access, --post-file, or --script), which could lead to Local File Inclusion (LFI) and Server-Side Request Forgery (SSRF) when rendering untrusted HTML strings.

To resolve this issue, we introduce a secure options allowlist approach that validates and filters meta options by default, while retaining full backward compatibility for trusted content through an override parameter.


🛠️ Changes Include

  • 🔒 Security Allowlist (pdfkit/security.py): Added an explicit allowlist of layout/formatting options (e.g., page-size, orientation, margins) that are safe to parse.
  • 🛡️ Validation Engine (pdfkit/pdfkit.py): Updated _find_options_in_meta to filter parsed options against the allowlist and emit a RuntimeWarning when a dangerous option is blocked.
  • 🔑 API Enhancement (pdfkit/api.py): Exposed the parameter allow_unsafe_meta_tags=False in from_string to give developers a secure fallback to restore legacy behavior if rendering trusted content.
  • 🧪 Regression Tests (tests/pdfkit-tests.py): Added TestPDFKitSecurity to fully test default safe behavior, allowlist restrictions, parameter propagation, and warnings.
  • 📝 Documentation (README.rst, HISTORY.rst): Documented the vulnerability fix, provided migration guidance, bumped package version to 2.0.1, and documented version changes.
  • 🙈 Git Cleanliness (.gitignore): Added .DS_Store to git ignore rules to prevent tracking environment files.

🧪 Test Plan

Verified that all 50 unit and integration tests pass successfully:

$ cd tests && PATH="$(pwd)/bin:$PATH" python pdfkit-tests.py
..................................................
----------------------------------------------------------------------
Ran 50 tests in 0.472s

OK

…VE-2025-26240

Create pdfkit/security.py containing ALLOWED_META_OPTIONS to filter safe/unsafe wkhtmltopdf parameters.
Modify pdfkit.py to integrate security checks in meta option extraction and issue warnings for blocked tags.
Add and document allow_unsafe_meta_tags parameter in from_string to support overriding the security filter if required.
Ensure default meta tags behavior blocks unsafe options, allowlist behaves as expected, and override works.
Update README.rst with security details, allowlist info, and usage instructions for the new parameter.
Bump version to 2.0.1 to release the security fix.
Add version 2.0.1 changelog entries highlighting the CVE-2025-26240 vulnerability fix.
Add .DS_Store to the git ignore configuration to prevent accidental tracking.
@crazyse

crazyse commented Jun 22, 2026

Copy link
Copy Markdown

@AdnanMuhib I'm unsure your PR will be approved. This repository has not been maintained since years.
I'm myself patched my project and planning to switch to another maintained Python library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants