Forum
10:22
17/05/2009
within grid.base.js, there is:
parse : function(jsonString) {
var js = jsonString;
if (js.substr(0,9) == "while(1);") { js = js.substr(9); }
if (js.substr(0,2) == "/*") { js = js.substr(2,js.length-4); }
if(!js) { js = "{}"; }
with(window) {
return eval('('+js+')');
}
},
using eval() poses quite some hacking potential; and better browser nowadays have included an ultra-opimized JSON-parser with the global JSON object. An easy substitute is to:
a) include
(public domain code)
b) replace that lines with
parse : function(jsonString) {
return JSON.parse(jsonString);
},
json2.js makes sure that the native browser JSON-parser gets used if available, and otherwise is better protected against injection of malicous code.
Harald
22:35
Moderators
30/10/2007
Hello,
Thanks. Why do you think that this is a bug?
Also do the following - after you load the jqGrid JS files include in your load the ultra-opimized JSON-parser and do the following
<script>
$.extend($.jgrid, {
parse : function(jsonString) {
return JSON.parse(jsonString);
}
})
</script>
This will overwrite the jqGrid parse function.
Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
06:40
17/05/2009
Tony,
> Thanks. Why do you think that this is a bug?
"bug" may be a hard word 🙂 But there is no forum for "potential security risks" ....
It may be an unecessary security risk - as eval() may have side effects. (probably the reason for the "protect against while(1) at the beginning)
Mozilla took its time to implement the global JSON-object for a reason - as eval() has to take more care then "unserialize an object". I did not time it, but would bet that on recent browser native JSON.parse is faster then eval()
Thanks for that .extend - that can help me in other situations, too!
best wishes
Harald
Most Users Ever Online: 715
Currently Online:
74 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66