summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2012-05-19 11:28:46 -0700
committerBharat Mediratta <bharat@menalto.com>2012-05-19 11:31:25 -0700
commita9be0691d9efd84cbf5a9f05236caf4df23bcfdb (patch)
tree2b5bcf6ecefb5e93d1f00cb450dd8625fcabfe23 /lib
parent74fa9422db01fbc017ddbc847333cc7847f185ab (diff)
Create an ajax response framework that inserts <meta> tags to guard
against UTF-7, and create a $.gallery_autocomplete variant of jQuery's autocomplete that expects the first line to be a <meta> tag and discards it. More complete fix for #1871.
Diffstat (limited to 'lib')
-rw-r--r--lib/gallery.common.js28
1 files changed, 28 insertions, 0 deletions
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 <meta> 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("<meta") == -1) {
+ throw 'Missing <meta> tag in first line of autocomplete response';
+ }
+ rows.shift(); // drop <META> 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);