🔒 FIX: escape user content in renderers and harden attrs default#150
Open
chrisjsewell wants to merge 1 commit into
Open
🔒 FIX: escape user content in renderers and harden attrs default#150chrisjsewell wants to merge 1 commit into
chrisjsewell wants to merge 1 commit into
Conversation
Addresses the XSS advisories reported against default configurations in #143: - texmath: HTML-escape math content and equation-number labels in the default renderer (consistent with dollarmath/amsmath). Input such as `$<img src=x onerror=alert(1)>$` previously emitted live markup. - dollarmath: escape equation labels in the generated `id` attribute and the permalink `href`. - myst_block: escape target labels `(name)=` in the rendered anchor. - attrs/attrs_block: when no `allowed` list is given, strip event-handler (`on*`) and `style` attributes by default (kept in meta `insecure_attrs`). Text spans `[text]{...}` now also honour the `allowed` list, which they previously bypassed. This is a baseline protection, not a full sanitiser. The admonition ReDoS (advisory 4) is addressed separately in #148. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01DS3iVi5q1TepHaMymmmeJy
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #150 +/- ##
==========================================
+ Coverage 92.80% 93.01% +0.20%
==========================================
Files 31 40 +9
Lines 1835 2290 +455
==========================================
+ Hits 1703 2130 +427
- Misses 132 160 +28
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Addresses the XSS advisories reported against default configurations in #143 (thanks to @KrisKennawayDD / Datadog for the detailed write-ups).
Each fix was reproduced against current
masterbefore and after, and covered by a regression test.Advisories addressed
texmathdollarmath/amsmathdollarmathidattribute and permalinkhrefmyst_block(name)=in the rendered anchorattrs/attrs_blockallow arbitrary event handlers by defaultallowedlist is given, strip event-handler (on*) andstyleattributes by defaultNotes on the
attrschange (#5)This is the one behavioural change, so calling it out:
allowedlist,on*andstyleattributes are now removed by default (moved intotoken.meta["insecure_attrs"], same mechanism as the existing allow-list). Benign attributes (width,data-*,class, …) are unaffected.("id", "class")) to avoid breaking the plugin's core "add arbitrary attributes" feature for the common trusted-content case. This is a baseline protection, not a full sanitiser — it won't stop e.g.href="javascript:"; untrusted input should still pass an explicitallowedlist. Documented in both docstrings and the changelog. Happy to switch to the stricter allow-list default if preferred.[text]{...}) assignedtoken.attrsdirectly and bypassed_add_attrsentirely — so it ignored theallowedallow-list too, not just the new denylist. That path (the advisory's own PoC,[click me]{onclick=...}) now routes through the filter, so an explicitallowedlist finally applies to spans as well.Tests & fixtures
test_texmath,test_dollarmath,test_myst_block,test_attrs).texmath_dollar.md,texmath_bracket.md,myst_block.md) that previously encoded the unescaped output; only the expected blocks changed, inputs untouched. Notablytexmathnow matches whatdollarmathalready did for the same$1+1<3$input.ruff,ruff format, andmypy --strictall clean.