feat: harden body HTML sanitization and PDF remote resource blocking#77
Merged
Conversation
dc07c5b to
360150a
Compare
Complete the remaining scope from issue #68: - scripts/markdown_to_html.py: add sanitize_html() using nh3 with a strict allowlist of safe tags and attributes. Strips script, iframe, event handlers, inline style, img, and javascript: URLs. Integration runs after all post-processing. - scripts/render_pdf.py: add --allow-remote flag (opt-out, HTTP/HTTPS BLOCKED by default). Route uses **/* with scheme check, covering all http/https URLs including those with paths. - scripts/md_to_pdf.py: add --allow-remote passthrough (opt-out). - requirements.txt: add nh3>=0.2 - scripts/test_remote_block.py: standalone test that spawns local HTTP server, verifies default mode blocks all remote requests and --allow-remote permits them. - CI: expand tests to cover style stripping, img removal, and remote-blocked PDF generation. Closes #68
360150a to
0570659
Compare
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
完成 #68 剩余 scope:body HTML sanitization + PDF HTTP/HTTPS 资源默认阻断。
改动
scripts/markdown_to_html.pysanitize_html()用nh3做 allowlist 过滤:移除<script>、<iframe>、onerror=、javascript:URL、style属性、<img>;只允许安全标签和属性scripts/render_pdf.py--allow-remote(opt-out,默认阻断 HTTP/HTTPS);路由用**/*+ scheme 判断scripts/md_to_pdf.py--allow-remote透传(opt-out,默认阻断)requirements.txtnh3>=0.2.github/workflows/ci.yml安全模型
html.escape()— 4 个字段nh3sanitization —style和img移除,dangerous tags stripped--allow-remote显式放开Closes #68