From a9be0691d9efd84cbf5a9f05236caf4df23bcfdb Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 19 May 2012 11:28:46 -0700 Subject: Create an ajax response framework that inserts tags to guard against UTF-7, and create a $.gallery_autocomplete variant of jQuery's autocomplete that expects the first line to be a tag and discards it. More complete fix for #1871. --- lib/gallery.common.js | 28 +++++++++++++++++++ modules/g2_import/controllers/admin_g2_import.php | 2 +- modules/g2_import/views/admin_g2_import.html.php | 2 +- modules/gallery/helpers/ajax.php | 31 ++++++++++++++++++++++ .../server_add/controllers/admin_server_add.php | 3 ++- modules/server_add/views/admin_server_add.html.php | 2 +- modules/tag/controllers/tags.php | 4 +-- modules/tag/helpers/tag_event.php | 4 +-- modules/tag/views/tag_block.html.php | 2 +- 9 files changed, 69 insertions(+), 9 deletions(-) create mode 100644 modules/gallery/helpers/ajax.php diff --git a/lib/gallery.common.js b/lib/gallery.common.js index b499a2cd..755218f5 100644 --- a/lib/gallery.common.js +++ b/lib/gallery.common.js @@ -222,4 +222,32 @@ }); }; + // Augment jQuery autocomplete to expect the first response line to + // be a tag that protects against UTF-7 attacks. + $.fn.gallery_autocomplete = function(url, options) { + // Drop the first response - it should be a meta tag + options.parse = function(data) { + var parsed = []; + var rows = data.split("\n"); + if (rows[0].indexOf(" tag in first line of autocomplete response'; + } + rows.shift(); // drop tag + for (var i=0; i < rows.length; i++) { + var row = $.trim(rows[i]); + if (row) { + row = row.split("|"); + parsed[parsed.length] = { + data: row, + value: row[0], + result: row[0] + }; + } + } + return parsed; + }; + + $(this).autocomplete(url, options); + }; + })(jQuery); diff --git a/modules/g2_import/controllers/admin_g2_import.php b/modules/g2_import/controllers/admin_g2_import.php index b07082c9..5edd2a1b 100644 --- a/modules/g2_import/controllers/admin_g2_import.php +++ b/modules/g2_import/controllers/admin_g2_import.php @@ -113,7 +113,7 @@ class Admin_g2_import_Controller extends Admin_Controller { } } - print implode("\n", $directories); + ajax::response(implode("\n", $directories)); } private function _get_import_form() { diff --git a/modules/g2_import/views/admin_g2_import.html.php b/modules/g2_import/views/admin_g2_import.html.php index 9c4eb840..22e19f5b 100644 --- a/modules/g2_import/views/admin_g2_import.html.php +++ b/modules/g2_import/views/admin_g2_import.html.php @@ -3,7 +3,7 @@ script("jquery.autocomplete.js") ?>