Last modified: 2014-11-18 18:07:33 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T21528, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 19528 - XSLT parameter to API queries
XSLT parameter to API queries
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
API (Other open bugs)
unspecified
All All
: Normal enhancement with 2 votes (vote)
: ---
Assigned To: Bryan Tong Minh
: patch, patch-need-review
: 20939 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-07-05 05:57 UTC by Tisza Gergő
Modified: 2014-11-18 18:07 UTC (History)
12 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
Adds xslt parameter to format=xml (1.56 KB, patch)
2009-07-11 11:28 UTC, Bryan Tong Minh
Details
make it send a mime type that more browsers recognize (1.06 KB, patch)
2009-11-24 03:30 UTC, Bawolff (Brian Wolff)
Details

Description Tisza Gergő 2009-07-05 05:57:01 UTC
Most API queries offer more flexibility than the corresponding special pages, so they could be used to create extended versions of those pages on the wiki, but formatting the results with javascript is somewhat cumbersome. XSLT would be much more suited to the task. It would be nice to have an optional XSLT parameter pointing to an XSLT file so that editors could simply use the API result page with XML format and the given transformation file, and their browser would format the results accordingly. This might be a potential XSS vector so such files should be restricted to the MediaWiki namespace and possibly the user's own space.
Comment 1 Roan Kattouw 2009-07-06 21:51:34 UTC
Processing of the XML output should be done client-side, not server-side, and certainly not in a way that introduces XSS vulnerabilities. Closing as WONTFIX.
Comment 2 Bryan Tong Minh 2009-07-10 14:34:10 UTC
(In reply to comment #1)
> Processing of the XML output should be done client-side, not server-side, and
> certainly not in a way that introduces XSS vulnerabilities. Closing as WONTFIX.
> 
The processing will still be done client-side: The bug opener refers to the <?xml-stylesheet href="location-to.xsl" type="text/xsl" ?> which could optionally be added to the top of the XML document in order to have a direct transformation when viewed in the web browser.
Comment 3 Tisza Gergő 2009-07-10 23:57:17 UTC
And it does not introduce any new XSS vulnerabilities if the XSLT file must come from the MediaWiki namespace; those who can write it can make XSS attacks much easier through the site-wide JS files.
Comment 4 Victor Vasiliev 2009-07-11 06:18:18 UTC
(In reply to comment #2)
> The processing will still be done client-side: The bug opener refers to the
> <?xml-stylesheet href="location-to.xsl" type="text/xsl" ?> which could
> optionally be added to the top of the XML document in order to have a direct
> transformation when viewed in the web browser.
> 

And what if someone points to a malicious XSLT? E.g. api.php?action=query&xslt=http://malicious.site/steal-cookies.xslt

Also, this is API. *Application* programming interface. It's not intended to format a user-readable output. I suggest WONTFIX.
Comment 5 Tisza Gergő 2009-07-11 09:13:40 UTC
(In reply to comment #4)
> And what if someone points to a malicious XSLT? E.g.
> api.php?action=query&xslt=http://malicious.site/steal-cookies.xslt

As I said in the summary, XSLT files should be restricted to the MediaWiki namespace: for example, api.php?action=query&xslt=foo could be translated to <?xml-stylesheet href="http://wiki.domain/wiki/MediaWiki:XSLT-foo.xsl" type="text/xsl" ?>. Anyone with malicious intent and write access to the MW namespace can already pull far worse tricks.
 
> Also, this is API. *Application* programming interface. It's not intended to
> format a user-readable output. I suggest WONTFIX.

And it would not format a user-readable output; it would format the exact same output with an XSLT header added. One could argue that the application is the browser in this case, were not arguments about the semantics of the A in API utterly pointless. Are there any actual drawbacks in allowing administrators to create user-readable formats of queries (with links to the relevant tools etc.) in a template-like format instead of a procedural language (JavaScript) which is much less convenient for this task?
Comment 6 Bryan Tong Minh 2009-07-11 11:28:09 UTC
Created attachment 6322 [details]
Adds xslt parameter to format=xml

Untested patch that adds a stylesheet declaration in the form MediaWiki:<xslt>.xslt.

Possible problems:
* Content-type: Does it matter for browsers which content type the stylesheet is served with?
* Can the URL be local or is it required to be full?
* If non-existent title or invalid title is given, fails silently. It could throw an error, but maybe it is better if simply the raw XML is given. (Perhaps indicate the error in a comment?)
Comment 7 Roan Kattouw 2009-07-11 18:28:07 UTC
(In reply to comment #6)
> Created an attachment (id=6322) [details]
> Adds xslt parameter to format=xml
> 
> Untested patch that adds a stylesheet declaration in the form
> MediaWiki:<xslt>.xslt.
> 
Patch reviewed, feel free to commit after testing.

> Possible problems:
> * Content-type: Does it matter for browsers which content type the stylesheet
> is served with?
> * Can the URL be local or is it required to be full?
> * If non-existent title or invalid title is given, fails silently. It could
> throw an error, but maybe it is better if simply the raw XML is given. (Perhaps
> indicate the error in a comment?)
> 
Throwing a warning is probably best.
Comment 8 Bryan Tong Minh 2009-07-11 19:54:50 UTC
Should the parameter be xslt= or xsl= ? Furthermore I believe that the extension should be .xsl, right?
Comment 9 Platonides 2009-07-11 20:20:54 UTC
There should also be an option for using its own stylesheets (eg. user Foo can use User:Foo/skin.xls).
That would need to add that extension as user-page protected. 
At least, the parameter should contain the namespace for future compatibility of the above use case.

Comment 10 Bryan Tong Minh 2009-07-13 21:38:30 UTC
Done in r53194 .
Comment 11 Brion Vibber 2009-08-22 17:20:16 UTC
Can't the client-side processing add in the XSLT reference itself from the consumed XML? This seems unnecessary.
Comment 12 Tisza Gergő 2009-08-22 18:03:16 UTC
You could add a site-wide javascript which checks if the user is on a certain page, gets the XML file via an AJAX query and adds the XSLT file, but having a query parameter for it is much more straightforward, and does not require JS code that will be downloaded by all users but never used by most.
Comment 13 Bawolff (Brian Wolff) 2009-09-29 01:36:31 UTC
Note, the parameter should add the header:
<?xml-stylesheet href="location-to.xsl" type="text/xsl" ?>

not
<?xml-stylesheet href="location-to.xsl" type="text/xml" ?>

As text/xml is not recognized by all browsers (see [[w:XSLT]]). Internet explorer in paticular seems to need text/xsl . 
Comment 14 Alexandre Emsenhuber [IAlex] 2009-10-02 08:41:39 UTC
*** Bug 20939 has been marked as a duplicate of this bug. ***
Comment 15 Bawolff (Brian Wolff) 2009-11-23 23:12:21 UTC
Note, in addition, some browsers (older gecko based browsers) are strict about mime type that the xslt is sent with.

Pretty please (With a cherry on top) make the xslt file be sent with a mime type of application/xml and change the <?xml-stylesheet line to:
<?xml-stylesheet href="location-to.xsl" type="text/xsl" ?>

This would actually make this work on a wide variaty of browsers.
Comment 16 Bawolff (Brian Wolff) 2009-11-24 03:30:21 UTC
Created attachment 6820 [details]
make it send a mime type that more browsers recognize

This makes the type attribute on <?xml-stylesheet processing instruction be text/xsl, which is recognized by all browsers (in paticular internet explorer; see [[w:xslt]]). It also allows pages in mediawiki namespace to be sent using mime type application/xml, which is a more technically correct mime type for xslt compared to text/x-wiki. (old mozilla (1.8) requires this, however old mozilla also does not recognize &amp;'s in <?xml-stylesheet?> processing instruction, so that part is not really needed, as old mozilla will not work regardless.)
Comment 17 Bryan Tong Minh 2010-01-16 21:49:32 UTC
I'm passing this through Tim before I apply it, as he changed the mimetype in r55749.
Comment 18 Tim Starling 2010-01-17 04:53:55 UTC
It's fine, you can revert me.
Comment 19 Bryan Tong Minh 2010-01-23 15:28:42 UTC
r61419

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links