Skip to content

Sanitizer: apply URI scheme check to xlink:href - #620

Open
A2wkiller wants to merge 1 commit into
kurtmckee:mainfrom
A2wkiller:fix-svg-xlink-href-scheme-check
Open

A2wkiller wants to merge 1 commit into
kurtmckee:mainfrom
A2wkiller:fix-svg-xlink-href-scheme-check

Conversation

@A2wkiller

Copy link
Copy Markdown

Summary

The HTML sanitizer only validated the URI scheme of plain href attributes. SVG content uses xlink:href (e.g. on <a>, <set>, <animate>), which was passed through untouched, so a javascript: URI survived sanitization inside inline SVG.

Fix: run xlink:href values through the same make_safe_absolute_uri scheme check as href in HTMLSanitizer.unknown_starttag.

Reproducer (before this change)

import feedparser.sanitizer
html = ('<svg xmlns="http://www.w3.org/2000/svg">'
        '<a xlink:href="javascript:alert(1)"><text>click</text></a></svg>')
print(feedparser.sanitizer.sanitize_html(html, None, "text/html"))
# -> xlink:href="javascript:alert(1)" kept in output

After this change the javascript: URI is stripped, matching the behavior of HTML href attributes.

Tests

  • Added three regression tests to tests/test_sanitizer.py covering xlink:href on SVG <set>/<a> with a javascript: scheme (stripped) and with an https: scheme (preserved). They fail before the fix and pass after.
  • Full suite: 4302 passed; the 6 failures in test_encoding.py/test_ill_formed.py also 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.

Copilot AI balanced review requested due to automatic review settings November 22, 2026 04:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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 href scheme check to xlink:href without changing element or attribute allowlists.
  • Adds three regression tests covering unsafe javascript: links on SVG elements and preservation of safe https: 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SVG XSS Sanitizer Bypass in feedparser (Python RSS/Atom Library)

2 participants