Skip to content

Commit 0106bcd

Browse files
committed
Further mitigation of handlebars-lang#1736
1 parent 30e3ed9 commit 0106bcd

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/handlebars/runtime.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,28 @@ export function template(templateSpec, env) {
6969
if (!(name in obj)) {
7070
throw new Exception('"' + name + '" not defined in ' + obj);
7171
}
72-
return obj[name];
72+
return container.lookupProperty(obj, name);
73+
},
74+
lookupProperty: function(parent, propertyName) {
75+
let result = parent[propertyName];
76+
if (result == null) {
77+
return result;
78+
}
79+
if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
80+
return result;
81+
}
82+
83+
if (!Utils.dangerousPropertyRegex.test(String(propertyName))) {
84+
return result;
85+
}
86+
87+
return undefined;
7388
},
7489
lookup: function(depths, name) {
7590
const len = depths.length;
7691
for (let i = 0; i < len; i++) {
77-
if (depths[i] && depths[i][name] != null) {
92+
let result = depths[i] && container.lookupProperty(depths[i], name);
93+
if (result != null) {
7894
return depths[i][name];
7995
}
8096
}

spec/security.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ describe('security issues', function() {
22
describe('GH-1495: Prevent Remote Code Execution via constructor', function() {
33
checkPropertyAccess({});
44

5+
describe('in compat-mode', function() {
6+
checkPropertyAccess({ compat: true });
7+
});
8+
59
describe('in strict-mode', function() {
610
checkPropertyAccess({ strict: true });
711
});

0 commit comments

Comments
 (0)