Repository navigation
🐛 fix(sanitize): check each value in the form XML output writes - #2116
Conversation
The XML serializer drops each character XML 1.0 cannot hold, which joins the two characters around it. The sanitizer's checks read the value with those characters still in place, so a value they cleared could turn into CSS, a URL, a template marker or a meta refresh they refuse once written as XML. This hit Policy(xml=True) output, and a sanitize_node() tree from an HTML-mode policy that is later written with inner_xml. Every check that reads a value now also judges the form the XML serializer writes, in both modes, and the value survives only when both pass. The CSS scrubbers rescrub their output's XML form when it holds such a character, the template-marker pass pairs delimiters across them, and the URL, srcset, refresh, value allowlist and predicate checks run on both forms. HTML output keeps the characters whenever both forms pass. Fixes tox-dev#1728
Merging this PR will degrade performance by 6.28%2 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
The sanitizer checked values as written, but the XML serializer drops every character that XML 1.0 cannot hold, and dropping one joins the characters around it. Once written as XML, a passing value could turn into a CSS declaration, a
url(), anexpression(), a template marker or a<meta>refresh that the same checks refuse in plain form. This reachedPolicy(xml=True)output, and also trees fromsanitize_node()under an HTML-mode policy when written withinner_xml. 🔒 After this change each check keeps a value only when it passes both the written form and the XML form.Architecture
The CSS scrubber, the template-marker pass, the URL checks, the refresh test and the policy callbacks each judge the value in both forms. Values written by
attribute_filterandset_attributespass through the same checks, and literalattribute_valuesentries must list both forms. The tree is the same whichever serializer writes it, so the rule applies in both modes. Comments need no change, since the serializer's comment guards already skip the dropped characters.Behavior changes
attribute_predicateis called a second time, without those characters, for a value that holds them, and both calls must return true.Fixes #1728.