🔒 Fix CVE-2025-26240: Secure HTML Meta Tag Option Parsing#276
Open
AdnanMuhib wants to merge 8 commits into
Open
🔒 Fix CVE-2025-26240: Secure HTML Meta Tag Option Parsing#276AdnanMuhib wants to merge 8 commits into
AdnanMuhib wants to merge 8 commits into
Conversation
…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.
|
@AdnanMuhib I'm unsure your PR will be approved. This repository has not been maintained since years. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔒 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 thepdfkit-prefix allowed the injection of arbitrarywkhtmltopdfoptions (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
pdfkit/security.py): Added an explicit allowlist of layout/formatting options (e.g.,page-size,orientation,margins) that are safe to parse.pdfkit/pdfkit.py): Updated_find_options_in_metato filter parsed options against the allowlist and emit aRuntimeWarningwhen a dangerous option is blocked.pdfkit/api.py): Exposed the parameterallow_unsafe_meta_tags=Falseinfrom_stringto give developers a secure fallback to restore legacy behavior if rendering trusted content.tests/pdfkit-tests.py): AddedTestPDFKitSecurityto fully test default safe behavior, allowlist restrictions, parameter propagation, and warnings.README.rst,HISTORY.rst): Documented the vulnerability fix, provided migration guidance, bumped package version to2.0.1, and documented version changes..gitignore): Added.DS_Storeto git ignore rules to prevent tracking environment files.🧪 Test Plan
Verified that all 50 unit and integration tests pass successfully: