Repository navigation
Conversation
There was a problem hiding this comment.
🔵 Needs a closer look
Human security review and browser-level validation are needed to determine whether the narrow xlink:href fix also addresses the SVG animate/set mutation vectors reported in #619.
No open issues 🎉
What changed in this PR
Extends feedparser’s HTML sanitizer URI-scheme validation to SVG xlink:href attributes, addressing the direct-link bypass reported in #619.
Changes:
- Applies the existing
hrefscheme check toxlink:hrefwithout changing element or attribute allowlists. - Adds three regression tests covering unsafe
javascript:links on SVG elements and preservation of safehttps:links.
| File | Description |
|---|---|
tests/test_sanitizer.py |
Adds unsafe- and safe-scheme regression tests for SVG xlink:href. |
feedparser/sanitizer.py |
Includes xlink:href in the existing URI-scheme validation. |
Review effort: Balanced
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
The HTML sanitizer only validated the URI scheme of plain
hrefattributes. SVG content usesxlink:href(e.g. on<a>,<set>,<animate>), which was passed through untouched, so ajavascript:URI survived sanitization inside inline SVG.Fix: run
xlink:hrefvalues through the samemake_safe_absolute_urischeme check ashrefinHTMLSanitizer.unknown_starttag.Reproducer (before this change)
After this change the
javascript:URI is stripped, matching the behavior of HTMLhrefattributes.Tests
tests/test_sanitizer.pycoveringxlink:hrefon SVG<set>/<a>with ajavascript:scheme (stripped) and with anhttps:scheme (preserved). They fail before the fix and pass after.test_encoding.py/test_ill_formed.pyalso occur on a clean checkout (pre-existing, environment-related).Security check
The change only widens the scheme check to an additional attribute; no allowlisted element or attribute was added or removed.
Fixes #619
Disclosure: this patch was prepared with AI assistance and reviewed/tested by me.