fix: disallow the use of constructors in templates

This closes a major security leak that allows execution of arbitrary
code in a NodeJS environment by creating a special Handlebars template.
This commit is contained in:
Nils Knappmeier
2019-01-30 22:21:44 +01:00
parent bacd473fe6
commit d3e8e46095
3 changed files with 27 additions and 0 deletions
@@ -13,6 +13,9 @@ JavaScriptCompiler.prototype = {
// PUBLIC API: You can override these methods in a subclass to provide
// alternative compiled forms for name lookup and buffering semantics
nameLookup: function(parent, name/* , type*/) {
if (name === 'constructor') {
return ['(', parent, '.propertyIsEnumerable(\'constructor\') ? ', parent, '.constructor : undefined', ')'];
}
if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
return [parent, '.', name];
} else {