]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/LinkPreview/actions/oembedproxy.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / plugins / LinkPreview / actions / oembedproxy.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * StatusNet-only extensions to the Twitter-like API
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @package   StatusNet
23  * @author    Brion Vibber <brion@status.net>
24  * @copyright 2010 StatusNet, Inc.
25  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
26  * @link      http://status.net/
27  */
28
29 if (!defined('STATUSNET') && !defined('LACONICA')) {
30     exit(1);
31 }
32
33 /**
34  * Oembed proxy implementation
35  *
36  * This class provides an interface for our JS-side code to pull info on
37  * links from other sites, using either native oEmbed, our own custom
38  * handlers, or the noembed.com offsite proxy service as configured.
39  *
40  * @category  oEmbed
41  * @package   StatusNet
42  * @author    Brion Vibber <brion@status.net>
43  * @copyright 2010 StatusNet, Inc.
44  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45  * @link      http://status.net/
46  */
47 class OembedproxyAction extends OembedAction
48 {
49     function handle($args)
50     {
51         // Trigger short error responses; not a human-readable web page.
52         GNUsocial::setApi(true);
53
54         // We're not a general oEmbed proxy service; limit to valid sessions.
55         $token = $this->trimmed('token');
56         if (!$token || $token != common_session_token()) {
57             // TRANS: Client error displayed when the session token does not match or is not given.
58             $this->clientError(_m('There was a problem with your session token. '.
59                                  'Try again, please.'));
60         }
61
62         $format = $this->arg('format');
63         if ($format && $format != 'json') {
64             // TRANS: Client exception thrown when requesting a different format than JSON.
65             throw new ClientException(_m('Invalid format; only JSON supported.'));
66         }
67
68         $url = $this->arg('url');
69         if (!common_valid_http_url($url)) {
70             // TRANS: Client exception thrown when not providing a valid URL.
71             throw new ClientException(_m('Invalid URL.'));
72         }
73
74         $params = array();
75         if ($this->arg('maxwidth')) {
76             $params['maxwidth'] = $this->arg('maxwidth');
77         }
78         if ($this->arg('maxheight')) {
79             $params['maxheight'] = $this->arg('maxheight');
80         }
81
82         $data = oEmbedHelper::getObject($url, $params);
83
84         $this->init_document('json');
85         print json_encode($data);
86     }
87 }