Skip to content

Commit dbca765

Browse files
[SS-4229] - Sidecar - Update handlebar to latest to address security vulnerabilities
1 parent 4fe125b commit dbca765

4 files changed

Lines changed: 23 additions & 11 deletions

File tree

lib/handlebars/compiler/compiler.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,15 @@ Compiler.prototype = {
7474
this.depths = {list: []};
7575
this.options = options;
7676

77-
// These changes will propagate to the other compiler components
78-
var knownHelpers = this.options.knownHelpers;
79-
this.options.knownHelpers = {
77+
this.options.knownHelpers = extend(Object.create(null), {
8078
'helperMissing': true,
8179
'blockHelperMissing': true,
8280
'each': true,
8381
'if': true,
8482
'unless': true,
8583
'with': true,
8684
'log': true
87-
};
88-
if (knownHelpers) {
89-
for (var name in knownHelpers) {
90-
this.options.knownHelpers[name] = knownHelpers[name];
91-
}
92-
}
85+
}, this.options.knownHelpers);
9386

9487
return this.accept(program);
9588
},

lib/handlebars/compiler/javascript-compiler.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ JavaScriptCompiler.prototype = {
2020
return 'Object.prototype.hasOwnProperty.call(' + parent + ',\'constructor\') ? ' + actual + ' : undefined';
2121
}
2222

23+
if (dangerousProperties.indexOf(name)) {
24+
const isEnumerable = [ this.aliasable('container.propertyIsEnumerable'), '.call(', parent, ',', JSON.stringify(name), ')']
25+
return ['(', isEnumerable, ' ? ', actual, ' : undefined)'];
26+
}
27+
2328
// Block the above dangerous properties altogether from being used. If they are used in a template, we assume it
2429
// could be to exploit the lib since the keywords don't make sense for actual template compilation or rendering
2530
// unlike 'constructor' which could be someone's occupation :) lol
@@ -100,6 +105,7 @@ JavaScriptCompiler.prototype = {
100105
this.hashes = [];
101106
this.compileStack = [];
102107
this.inlineStack = [];
108+
this.aliases = [];
103109

104110
this.compileChildren(environment, options);
105111

@@ -857,6 +863,20 @@ JavaScriptCompiler.prototype = {
857863
};
858864
},
859865

866+
aliasable: function(name) {
867+
let ret = this.aliases[name];
868+
if (ret) {
869+
ret.referenceCount++;
870+
return ret;
871+
}
872+
873+
ret = this.aliases[name] = this.source.wrap(name);
874+
ret.aliasable = true;
875+
ret.referenceCount =1;
876+
877+
return ret;
878+
},
879+
860880
setupOptions: function(paramSize, params) {
861881
var options = [], contexts = [], types = [], param, inverse, program;
862882

lib/handlebars/runtime.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
module Utils from "./utils";
21
import Exception from "./exception";
32
import { COMPILER_REVISION, REVISION_CHANGES } from "./base";
43

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"optimist": "~0.3"
2525
},
2626
"optionalDependencies": {
27-
"uglify-js": "~2.6"
27+
"uglify-js": "^3.14.3"
2828
},
2929
"devDependencies": {
3030
"async": "~0.2.9",

0 commit comments

Comments
 (0)