Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 35 additions & 15 deletions dist/amd/handlebars/compiler/javascript-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,45 @@ define(
// 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*/) {
var wrap,
ret;
if (parent.indexOf('depth') === 0) {
wrap = true;
}
const actual = _actualLookup();
const dangerousProperties = ['__defineGetter__','__defineSetter__','__lookupGetter__','__proto__'];

if (/^[0-9]+$/.test(name)) {
ret = parent + "[" + name + "]";
} else if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
ret = parent + "." + name;
// Do not allow to access constructor of any object/class
// See: https://snyk.io/vuln/SNYK-JS-HANDLEBARS-469063
if (name === 'constructor') {
return 'Object.prototype.hasOwnProperty.call(' + parent + ',\'constructor\') ? ' + actual + ' : undefined';
}
else {
ret = parent + "['" + name + "']";

// Block the above dangerous properties altogether from being used. If they are used in a template, we assume it
// could be to exploit the lib since the keywords don't make sense for actual template compilation or rendering
// unlike 'constructor' which could be someone's occupation :) lol
// See https://snyk.io/vuln/SNYK-JS-HANDLEBARS-534988
if (dangerousProperties.indexOf(name) !== -1) {
throw new Exception('For security reasons, you cannot use ' + name);
}

if (wrap) {
return '(' + parent + ' && ' + ret + ')';
} else {
return ret;
return actual;

// Original 1.3.0 code for nameLookup which we default back to if a special keyword is not used
function _actualLookup() {
var wrap,
ret;
if (parent.indexOf('depth') === 0) {
wrap = true;
}
if (/^[0-9]+$/.test(name)) {
ret = parent + "[" + name + "]";
} else if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
ret = parent + "." + name;
} else {
ret = parent + "['" + name + "']";
}

if (wrap) {
return '(' + parent + ' && ' + ret + ')';
} else {
return ret;
}
}
},

Expand Down
50 changes: 35 additions & 15 deletions dist/cjs/handlebars/compiler/javascript-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,45 @@ 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*/) {
var wrap,
ret;
if (parent.indexOf('depth') === 0) {
wrap = true;
}
const actual = _actualLookup();
const dangerousProperties = ['__defineGetter__','__defineSetter__','__lookupGetter__','__proto__'];

if (/^[0-9]+$/.test(name)) {
ret = parent + "[" + name + "]";
} else if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
ret = parent + "." + name;
// Do not allow to access constructor of any object/class
// See: https://snyk.io/vuln/SNYK-JS-HANDLEBARS-469063
if (name === 'constructor') {
return 'Object.prototype.hasOwnProperty.call(' + parent + ',\'constructor\') ? ' + actual + ' : undefined';
}
else {
ret = parent + "['" + name + "']";

// Block the above dangerous properties altogether from being used. If they are used in a template, we assume it
// could be to exploit the lib since the keywords don't make sense for actual template compilation or rendering
// unlike 'constructor' which could be someone's occupation :) lol
// See https://snyk.io/vuln/SNYK-JS-HANDLEBARS-534988
if (dangerousProperties.indexOf(name) !== -1) {
throw new Exception('For security reasons, you cannot use ' + name);
}

if (wrap) {
return '(' + parent + ' && ' + ret + ')';
} else {
return ret;
return actual;

// Original 1.3.0 code for nameLookup which we default back to if a special keyword is not used
function _actualLookup() {
var wrap,
ret;
if (parent.indexOf('depth') === 0) {
wrap = true;
}
if (/^[0-9]+$/.test(name)) {
ret = parent + "[" + name + "]";
} else if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
ret = parent + "." + name;
} else {
ret = parent + "['" + name + "']";
}

if (wrap) {
return '(' + parent + ' && ' + ret + ')';
} else {
return ret;
}
}
},

Expand Down
52 changes: 36 additions & 16 deletions dist/handlebars.amd.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!

handlebars v1.3.0-sugarcrm-temporary
handlebars v4.7.8-sugarcrm

Copyright (C) 2011 by Yehuda Katz

Expand Down Expand Up @@ -1764,25 +1764,45 @@ define(
// 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*/) {
var wrap,
ret;
if (parent.indexOf('depth') === 0) {
wrap = true;
}
const actual = _actualLookup();
const dangerousProperties = ['__defineGetter__','__defineSetter__','__lookupGetter__','__proto__'];

if (/^[0-9]+$/.test(name)) {
ret = parent + "[" + name + "]";
} else if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
ret = parent + "." + name;
// Do not allow to access constructor of any object/class
// See: https://snyk.io/vuln/SNYK-JS-HANDLEBARS-469063
if (name === 'constructor') {
return 'Object.prototype.hasOwnProperty.call(' + parent + ',\'constructor\') ? ' + actual + ' : undefined';
}
else {
ret = parent + "['" + name + "']";

// Block the above dangerous properties altogether from being used. If they are used in a template, we assume it
// could be to exploit the lib since the keywords don't make sense for actual template compilation or rendering
// unlike 'constructor' which could be someone's occupation :) lol
// See https://snyk.io/vuln/SNYK-JS-HANDLEBARS-534988
if (dangerousProperties.indexOf(name) !== -1) {
throw new Exception('For security reasons, you cannot use ' + name);
}

if (wrap) {
return '(' + parent + ' && ' + ret + ')';
} else {
return ret;
return actual;

// Original 1.3.0 code for nameLookup which we default back to if a special keyword is not used
function _actualLookup() {
var wrap,
ret;
if (parent.indexOf('depth') === 0) {
wrap = true;
}
if (/^[0-9]+$/.test(name)) {
ret = parent + "[" + name + "]";
} else if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
ret = parent + "." + name;
} else {
ret = parent + "['" + name + "']";
}

if (wrap) {
return '(' + parent + ' && ' + ret + ')';
} else {
return ret;
}
}
},

Expand Down
6 changes: 3 additions & 3 deletions dist/handlebars.amd.min.js

Large diffs are not rendered by default.

52 changes: 36 additions & 16 deletions dist/handlebars.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!

handlebars v1.3.0-sugarcrm-temporary
handlebars v4.7.8-sugarcrm

Copyright (C) 2011 by Yehuda Katz

Expand Down Expand Up @@ -1786,25 +1786,45 @@ var __module11__ = (function(__dependency1__, __dependency2__) {
// 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*/) {
var wrap,
ret;
if (parent.indexOf('depth') === 0) {
wrap = true;
}
const actual = _actualLookup();
const dangerousProperties = ['__defineGetter__','__defineSetter__','__lookupGetter__','__proto__'];

if (/^[0-9]+$/.test(name)) {
ret = parent + "[" + name + "]";
} else if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
ret = parent + "." + name;
// Do not allow to access constructor of any object/class
// See: https://snyk.io/vuln/SNYK-JS-HANDLEBARS-469063
if (name === 'constructor') {
return 'Object.prototype.hasOwnProperty.call(' + parent + ',\'constructor\') ? ' + actual + ' : undefined';
}
else {
ret = parent + "['" + name + "']";

// Block the above dangerous properties altogether from being used. If they are used in a template, we assume it
// could be to exploit the lib since the keywords don't make sense for actual template compilation or rendering
// unlike 'constructor' which could be someone's occupation :) lol
// See https://snyk.io/vuln/SNYK-JS-HANDLEBARS-534988
if (dangerousProperties.indexOf(name) !== -1) {
throw new Exception('For security reasons, you cannot use ' + name);
}

if (wrap) {
return '(' + parent + ' && ' + ret + ')';
} else {
return ret;
return actual;

// Original 1.3.0 code for nameLookup which we default back to if a special keyword is not used
function _actualLookup() {
var wrap,
ret;
if (parent.indexOf('depth') === 0) {
wrap = true;
}
if (/^[0-9]+$/.test(name)) {
ret = parent + "[" + name + "]";
} else if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
ret = parent + "." + name;
} else {
ret = parent + "['" + name + "']";
}

if (wrap) {
return '(' + parent + ' && ' + ret + ')';
} else {
return ret;
}
}
},

Expand Down
6 changes: 3 additions & 3 deletions dist/handlebars.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/handlebars.runtime.amd.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!

handlebars v1.3.0-sugarcrm-temporary
handlebars v4.7.8-sugarcrm

Copyright (C) 2011 by Yehuda Katz

Expand Down
2 changes: 1 addition & 1 deletion dist/handlebars.runtime.amd.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/handlebars.runtime.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!

handlebars v1.3.0-sugarcrm-temporary
handlebars v4.7.8-sugarcrm

Copyright (C) 2011 by Yehuda Katz

Expand Down
2 changes: 1 addition & 1 deletion dist/handlebars.runtime.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 2 additions & 9 deletions lib/handlebars/compiler/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,15 @@ Compiler.prototype = {
this.depths = {list: []};
this.options = options;

// These changes will propagate to the other compiler components
var knownHelpers = this.options.knownHelpers;
this.options.knownHelpers = {
this.options.knownHelpers = extend(Object.create(null), {
'helperMissing': true,
'blockHelperMissing': true,
'each': true,
'if': true,
'unless': true,
'with': true,
'log': true
};
if (knownHelpers) {
for (var name in knownHelpers) {
this.options.knownHelpers[name] = knownHelpers[name];
}
}
}, this.options.knownHelpers);

return this.accept(program);
},
Expand Down
Loading