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:
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:
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:
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) {}