Repository navigation
fix: security issues - #89
Merged
Merged
Conversation
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.
Summary
Fixes SSRF (CWE-918) and arbitrary local file read (CWE-73 / CWE-22) when converting untrusted HTML to DOCX. All versions up to and including 1.2.1 are affected.
Before this change, every
<img src>and<link rel="stylesheet" href>was fetched withurllib.request.urlopenoropen()with no restrictions, so attacker-controlled HTML could make the server request internal services and cloud metadata endpoints (e.g.169.254.169.254) or read arbitrary local files. Image responses were embedded into the generated.docx, exfiltrating their content.Advisory: GHSA-xh3w-67hm-58x9
What changed
Security
html4docx/resources.pymodule, governed by aResourcePolicybuilt fromparser.options.http/https. The opener only registers HTTP(S) handlers, sofile://,ftp://and other schemes are refused, including through redirects.local-files-root(..and symlinks resolved first).max-resource-bytes(10 MB by default).HTTP_PROXY/HTTPS_PROXYare ignored, since routing through a proxy would bypass the private network check (and avoids httpoxy).New options
allow-remote-resourcesTruehttp/httpsimages and stylesheets.private-network-allowlist[]ValueError.allow-private-networkFalselocal-files-rootNoneNonedisables local files.max-resource-bytes10485760Tests and CI
tests/test_security.pycovering SSRF via<img>and<link>, private/metadata IPs, redirects to private addresses, blocked schemes, size limit, local file confinement and path traversal, the allowlist, option precedence and the combined-options warning.local-files-root.pytest-xdistadded to speed up the test suite on CI.Docs
file://) are disabled by default. Setparser.options['local-files-root']; relative paths are now resolved against it instead of the current working directory.private-network-allowlist.HTTP_PROXY/HTTPS_PROXYare no longer honored when fetching remote resources.Public
http/httpsURLs anddata:image/...images work as before.Issue Reference
None
Checklist Before Requesting a Review