Repository navigation
Description
Problem
The shared safe-output HTML sanitizer removes selected attributes from ordinary HTML tags, but can leave the same attributes in place when they immediately follow the closing quote of another attribute without intervening whitespace.
For example, using a harmless title attribute:
<img src="https://github.com/example.png" title="example">
<img src="https://github.com/example.png"title="example">The first form has its title attribute removed by the current attribute filter. The quote-adjacent form does not match that filter, even though HTML parsers can recover the missing whitespace and interpret it as a separate attribute. The inconsistency also applies to the other attribute classes handled by the same filter.
Relevant implementation
Source reviewed at revision 4818bbd3c6ede6ac52082f0effda5892041af218:
stripDangerousAttributes()in sanitize_content_core.cjs:1259–1266 requires whitespace or/immediately before an attribute name. A closing quote directly before the name does not satisfy this condition.convertXmlTags():1269 onwardlocates tags with a flat regex, without tracking quoted attribute values.
These two routines should agree on tag and attribute boundaries, including recoverable malformed HTML. Simply broadening the separator regex could incorrectly modify text inside a legitimate quoted attribute value.
Expected behavior
For attributes that the sanitizer is configured to strip, quote-adjacent spelling should not cause the attribute to be preserved. Either remove the attribute using quote-aware parsing or neutralize unsupported malformed markup consistently. Preserve ordinary allowed HTML, safe attribute values, and HTTPS angle-bracket autolinks.
Suggested implementation and tests
- Use a small quote-aware tag/attribute scanner, or an existing suitable parser if available, rather than treating the entire tag as an unstructured string.
- Cover double- and single-quoted values, missing whitespace after a closing quote, quoted
>characters, self-closing tags, and unbalanced quotes. - Assert exact output through both
convertXmlTags()and the completesanitizeContentCore()pipeline. - Include harmless
title/data-*cases alongside the other filtered attribute classes, plus controls showing that matching text inside a safe quoted value is not mistaken for another attribute. - Preserve the existing URL-redaction boundary regressions and safe markup behavior.
Scope
This issue concerns consistency of the sanitizer's string-transformation contract. It does not claim that the resulting markup executes script in GitHub's UI: GitHub's rendering pipeline applies additional sanitization, and no new live rendering test or end-to-end reproduction was performed for this issue. The current-source assessment above identifies the remaining parsing/filtering mismatch.
Open issue/PR searches for the relevant function names, quote/attribute terminology, and related examples returned no matching report at filing time.
Activity