Page MenuHomePhabricator

mw.loader.inspect throws exceptions for CSS queries with pseudo elements
Closed, ResolvedPublic

Description

While debugging T112552, we discovered that mw.loader.inspect() on Safari and Firefox might throw exceptions for several types of CSS selectors.

The exception is a DOM Exception 12 SyntaxError.

The first cause of this was document.querySelector() being fed with actual invalid CSS queries on Commons.

The second cause is a bug/undefined behavior for vendor prefixed pseudo elements.

  1. Webkit fails on all of these
  2. Firefox throws an exception on vendor prefixes other than their own
  3. Chrome throws an exception on vendor prefix other than their own.

Event Timeline

TheDJ raised the priority of this task from to Needs Triage.
TheDJ updated the task description. (Show Details)
TheDJ subscribed.

Change 238439 had a related patch set uploaded (by Catrope):
Ignore exceptions from document.querySelector()

https://gerrit.wikimedia.org/r/238439

TheDJ set Security to None.

Change 238439 merged by jenkins-bot:
Ignore exceptions from document.querySelector()

https://gerrit.wikimedia.org/r/238439

This is currently listed in MW-1.26-release as a possible release blocker. Did Roan's patch fix this bug, or just sweep it under the carpet for now?

I don't think this needs to be a blocker, it was just tagged automatically by the bot since Roan's exception ignoring patch will make it in.

Krinkle claimed this task.
Krinkle triaged this task as Medium priority.
Krinkle moved this task from Inbox to Confirmed Problem on the MediaWiki-ResourceLoader board.

The Safari issue is fixed in the next Safari release. https://bugs.webkit.org/show_bug.cgi?id=149160
Greetings to the person who in x years from now is wondering why that try catch is needed and if it can be removed :)

For what it's worth, I don't think removing this try-catch is something we can do even if all supported browsers implement querySelector such that it accepts all selectors that they also accept in CSS.

The reason being that querySelector is required, by spec, to throw for selectors that the browser knows are not valid. This means, this particular bug aside, there will likely always be selectors somewhere in a stylesheet aimed at a different browser that a current browser might consider invalid. Plus, given user-generated contents, there can indeed also be selectors that aren't valid in any browser. Seems like that try-catch is here to stay!