Page MenuHomePhabricator

XSS in WDQS UI result view explore button
Closed, ResolvedPublicSecurity

Description

Example link (alerts “xss” on page load): https://query.wikidata.org/embed.html#SELECT%20(IRI(%22\%22%3E%3Cscript%3Ealert(\%22xss\%22)%3C%2Fscript%3E%3Ca%20href%3D\%22%2Fentity%2FQ123%22)%20AS%20%3Fx)%20{}

The following function creates HTML unsafely:

FormatterHelper.js
SELF.prototype.createExploreButton = function( url ) {
    var $button = $( '<a href="' + url +
            '" title="Explore item" class="explore glyphicon glyphicon-search" tabindex="-1" aria-hidden="true">' );
    $button.click( $.proxy( this.handleExploreItem, this ) );

    return $button;
};

It’s called here, with only a relatively simple guard on the url:

FormatterHelper.js formatValue
if ( this.isEntityUri( value ) ) {
    $html.prepend( this.createExploreButton( value ), ' ' );
}

But isEntityUri isn’t meant to be a check that this is an HTML-safe string, only that, assuming it’s a URI, it looks vaguely like an entity URI:

FormatterHelper.js
SELF.prototype.isEntityUri = function( uri ) {
    return typeof uri === 'string'
        && /\/entity\/(Q|P|L|M)[0-9]+$/.test( uri );
};

So you can put arbitrary HTML into an URI, and as long as it ends like an entity URI, and you’re using a result view that reaches this code (which includes the default Table view), it’ll be injected directly into the page. The link above uses:

SELECT (IRI("\"><script>alert(\"xss\")</script><a href=\"/entity/Q123") AS ?x) {}

Event Timeline

This is probably more severe than T298839 and T297686, since it results in script execution without user interaction. (But keep in mind that query.wikidata.org is not CORS-enabled.)

Tried it out locally and can confirm that it fixes the issue. Also, the code appears sensible. This has my virtual +1 as well and is ready to be applied as far as I'm concerned.

Patch seems sane, +1 from the Security-Team. Unfortunately, I still do not believe we have a great way to security deploy patches to wdqs (unless something has changed in the last week), so T297686#7584787 might still be the best deployment guidance we can provide at this time.

After a manual puppet run by @Volans (thanks), this and the fixes for T298839 and T297686 are deployed now. @Addshore and/or @Tarrow are working on releases for third-party installs, I believe.

Addshore changed the visibility from "Custom Policy" to "Public (No Login Required)".
Addshore changed the edit policy from "Custom Policy" to "All Users".