-
Notifications
You must be signed in to change notification settings - Fork 302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: CSP Security hole in tryConvertExpr (new Function(...)) #139
base: master
Are you sure you want to change the base?
fix: CSP Security hole in tryConvertExpr (new Function(...)) #139
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great suff....
My main concern is:
- Performance: Did you benchmark against old unsafe code?
- Large extra dependencies
Really need feedback from devs / owners on how important these are to evaluate the acceptability of the solutions
catch (e) { | ||
throw new Error('Invalid expression.'); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return func;
?
}; | ||
|
||
// Try run t | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove debug code
|
||
const func = function(width, height, dpr) { | ||
const context = { width, height, dpr }; | ||
const mexp = new Mexp() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the expressions are as simple as the bug implies then rather than ast and all the overhead of generating it perhaps simple str substitution and split could do the job.
This would remove the need for esprima
and the astToMathExpression()
function
This could be better but something like:
expression = expression.replaceAll('width", width).replaceAll('height", height).replaceAll('dpr", dpr).replaceAll("[", "").replaceAll("]", "");
expressions = expression.split(",")
if (expressions.length === 1) {
return mexp.eval(expressions[0]);
}
return [ mexp.eval(expressions[0]), mexp.eval(expressions[1]) ];
Probably needs some exception handling as well
|
||
const func = function(width, height, dpr) { | ||
const context = { width, height, dpr }; | ||
const mexp = new Mexp() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the const mexp
value move out of the func
scope so in instantiated for each call?
Addresses the CSP security hole identified in the issue linked below and allow ClayGL to be used on sites with strict Content Security Policies:
Please make claygl CSP compatible when "script-src unsafe-eval" is used.