Created
September 27, 2012 16:47
-
-
Save sharnik/3795055 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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