freegroup / draw2d

Create Visio like drawings, diagrams or workflows with JavaScript and HTML5
https://freegroup.github.io/draw2d/#/examples
MIT License
738 stars 227 forks source link

Use of eval("new "+className+"()") allows XSS when JSON is unmarshalled #183

Open rudolphi opened 3 years ago

rudolphi commented 3 years ago

Imagine className could be "String();doWhatever"

Better create a function to create the instances. Split the class name at dots, then go var base=window; base=base["first"]; and so on to get the desired class. Finally use one the approaches explained here https://stackoverflow.com/questions/3362471/how-can-i-call-a-javascript-constructor-using-call-or-apply https://stackoverflow.com/questions/1606797/use-of-apply-with-new-operator-is-this-possible to securely create the instance. The good thing is you never pass any parameters (14 times in 8 files), so the fix should not be a big deal.