From d1fb52264bc41a54061614772580377f200e90ee Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 16 Nov 2010 15:36:53 -0800 Subject: Use session token protection on oEmbed proxy action for LinkPreview... and commit the file *sigh* --- plugins/LinkPreview/linkpreview.js | 3 +- plugins/LinkPreview/oembedproxyaction.php | 84 +++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 plugins/LinkPreview/oembedproxyaction.php diff --git a/plugins/LinkPreview/linkpreview.js b/plugins/LinkPreview/linkpreview.js index 641adb729..0c0eb734e 100644 --- a/plugins/LinkPreview/linkpreview.js +++ b/plugins/LinkPreview/linkpreview.js @@ -54,7 +54,8 @@ url: url, format: 'json', maxwidth: oEmbed.width, - maxheight: oEmbed.height + maxheight: oEmbed.height, + token: $('#token').val() }; $.get(oEmbed.api, params, function(data, xhr) { callback(data); diff --git a/plugins/LinkPreview/oembedproxyaction.php b/plugins/LinkPreview/oembedproxyaction.php new file mode 100644 index 000000000..470f78073 --- /dev/null +++ b/plugins/LinkPreview/oembedproxyaction.php @@ -0,0 +1,84 @@ +. + * + * @package StatusNet + * @author Brion Vibber + * @copyright 2010 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET') && !defined('LACONICA')) { + exit(1); +} + +/** + * Oembed proxy implementation + * + * This class provides an interface for our JS-side code to pull info on + * links from other sites, using either native oEmbed, our own custom + * handlers, or the oohEmbed.com offsite proxy service as configured. + * + * @category oEmbed + * @package StatusNet + * @author Brion Vibber + * @copyright 2010 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +class OembedproxyAction extends OembedAction +{ + + function handle($args) + { + // We're not a general oEmbed proxy service; limit to valid sessions. + $token = $this->trimmed('token'); + if (!$token || $token != common_session_token()) { + $this->clientError(_('There was a problem with your session token. '. + 'Try again, please.')); + } + + $format = $this->arg('format'); + if ($format && $format != 'json') { + throw new ClientException('Invalid format; only JSON supported.'); + } + + $url = $this->arg('url'); + if (!common_valid_http_url($url)) { + throw new ClientException('Invalid URL.'); + } + + $params = array(); + if ($this->arg('maxwidth')) { + $params['maxwidth'] = $this->arg('maxwidth'); + } + if ($this->arg('maxheight')) { + $params['maxheight'] = $this->arg('maxheight'); + } + + $data = oEmbedHelper::getObject($url, $params); + + $this->init_document('json'); + print json_encode($data); + } + +} -- cgit v1.2.3-54-g00ecf