Skip to content

Commit 0d4e91e

Browse files
frenzymadnessclaude
andcommitted
docs: clarify _remove_attrs_that_bypass_link_cleaning docstring
Rewrap the docstring into a readable list, fix the over-long line, and spell out why srcdoc and the SVG animation value attributes are each unreachable by rewrite_links. No behaviour change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent e72a040 commit 0d4e91e

1 file changed

Lines changed: 21 additions & 11 deletions

File tree

‎lxml_html_clean/clean.py‎

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,27 @@ def _local_name(name):
144144

145145

146146
def _remove_attrs_that_bypass_link_cleaning(doc):
147-
"""Remove attributes that can run script but are not link attributes.
148-
149-
``srcdoc`` holds a whole HTML document rendered inside the iframe and
150-
takes priority over ``src``. ``to``/``from``/``by``/``values`` on
151-
``<set>``/``<animate>``/``<animateTransform>`` targeting ``href`` put a
152-
URL on the enclosing link at runtime. ``values`` is a ``;``-separated list, so these are
153-
dropped instead of being scheme-checked.
154-
155-
Names are compared case-insensitively and without namespace or prefix,
156-
and every match is handled, so XHTML trees with ``srcdoc`` and
157-
``SRCDOC``, or with a second ``attributename``, cannot hide one.
147+
"""Remove script-bearing attributes that ``rewrite_links`` cannot clean.
148+
149+
``rewrite_links`` only visits attributes listed in
150+
``lxml.html.defs.link_attrs``, so these two script vectors would
151+
otherwise survive ``safe_attrs_only=False``:
152+
153+
* ``srcdoc`` on ``<iframe>`` holds a whole HTML document that the browser
154+
renders inside the frame, and it takes priority over ``src`` -- so a
155+
whitelisted ``src`` does not make it safe. It is removed from every
156+
element.
157+
* ``to``/``from``/``by``/``values`` on ``<set>``/``<animate>``/
158+
``<animateTransform>`` whose ``attributeName`` is ``href`` (or
159+
``xlink:href``) set a URL on the enclosing SVG ``<a>`` at runtime.
160+
They are dropped rather than scheme-checked because ``values`` is a
161+
``;``-separated list, so a check on the whole string would miss
162+
individual items.
163+
164+
Attribute and tag names are matched case-insensitively and without any
165+
namespace or prefix, and every match on an element is handled. XHTML
166+
trees distinguish ``srcdoc`` from ``SRCDOC`` and may carry a second
167+
``attributeName``; neither can hide a dangerous attribute.
158168
"""
159169
for el in doc.iter(etree.Element):
160170
attrib = el.attrib

0 commit comments

Comments
 (0)