Skip to content

Instantly share code, notes, and snippets.

@mala
Created April 26, 2012 13:23
Show Gist options
  • Save mala/2499522 to your computer and use it in GitHub Desktop.
Save mala/2499522 to your computer and use it in GitHub Desktop.
jQuery XSS patch
(function(){
jQuery.fn.__init = jQuery.fn.init;
var old_expr = /^(?:[^<]*(<[\w\W]+>)[^>]*$)/;
var strict_expr = /^\s*</;
jQuery.fn.init = function(selector, context, rootjQuery){
if (typeof selector === "string") {
// console.log(selector);
if (old_expr.test(selector) && !strict_expr.test(selector)) {
throw 'Syntax error, html string must start with "<"';
}
}
return new jQuery.fn.__init(selector, context, rootjQuery);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment