Skip to content

Instantly share code, notes, and snippets.

@sharnik
Created September 27, 2012 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharnik/3795055 to your computer and use it in GitHub Desktop.
Save sharnik/3795055 to your computer and use it in GitHub Desktop.
/* Parse JSON hijacking protected strings: while(1);{ "foo": 1 } */
(function() {
var SECURITY_REG_EXP = /^while\(1\);([\s\S]*)\s*$/,
ORIGINAL_PARSEJSON = $.parseJSON;
$.extend($, {
stripSecurity: function(string) {
return string.replace(SECURITY_REG_EXP, "$1");
},
parseJSON: function(string) {
return ORIGINAL_PARSEJSON($.stripSecurity(string));
},
});
$.ajaxSetup({
dataFilter: function(data, type) {
return type === "json" ? $.stripSecurity(data) : data;
}
});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment