virtual-labs-archive / pattern-recognition-iiith

Other
4 stars 246 forks source link

eval can be harmful. (no-eval) #94

Open BSravanthi opened 5 years ago

BSravanthi commented 5 years ago

JavaScript's eval() function is potentially dangerous and is often misused. Using eval() on untrusted code can open a program up to several different injection attacks. The use of eval() in most contexts can be substituted for a better, alternative approach to a problem. This rule is aimed at preventing potentially dangerous, unnecessary, and slow code by disallowing the use of the eval() function. As such, it will warn whenever the eval() function is used.

//Bad:
var obj = { x: "foo" },
    key = "x",
    value = eval("obj." + key);

//Good:
var obj = { x: "foo" },
    key = "x",
    value = obj[key];

Please refer to the following link to fix similar issues. https://app.codacy.com/app/BSravanthi/pattern-recognition-iiith/issues?&filters=W3siaWQiOiJMYW5ndWFnZSIsInZhbHVlcyI6W251bGxdfSx7ImlkIjoiQ2F0ZWdvcnkiLCJ2YWx1ZXMiOlsiU2VjdXJpdHkiXX0seyJpZCI6IkxldmVsIiwidmFsdWVzIjpbbnVsbF19LHsiaWQiOiJQYXR0ZXJuIiwidmFsdWVzIjpbMTY2NF19LHsiaWQiOiJBdXRob3IiLCJ2YWx1ZXMiOltudWxsXX0seyJ2YWx1ZXMiOltdfV0=

samhithavootkoor commented 5 years ago

commit id: 9b80f64

snehitharangu commented 5 years ago

Valid fix @samhithavootkoor

somashekhar31 commented 5 years ago

validated-2 fix @samhithavootkoor