Skip to content

Commit d541378

Browse files
committed
fix: use String(field) in lookup when checking for "constructor"
closes #1603
1 parent c2ac79c commit d541378

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

lib/handlebars/helpers/lookup.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export default function(instance) {
33
if (!obj) {
44
return obj;
55
}
6-
if (field === 'constructor' && !obj.propertyIsEnumerable(field)) {
6+
if (String(field) === 'constructor' && !obj.propertyIsEnumerable(field)) {
77
return undefined;
88
}
99
return obj[field];

spec/security.js

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
describe('security issues', function() {
22
describe('GH-1495: Prevent Remote Code Execution via constructor', function() {
33
it('should not allow constructors to be accessed', function() {
4-
shouldCompileTo('{{constructor.name}}', {}, '');
5-
shouldCompileTo('{{lookup (lookup this "constructor") "name"}}', {}, '');
4+
expectTemplate('{{lookup (lookup this "constructor") "name"}}')
5+
.withInput({})
6+
.toCompileTo('');
7+
8+
expectTemplate('{{constructor.name}}')
9+
.withInput({})
10+
.toCompileTo('');
611
});
712

8-
it('should allow the "constructor" property to be accessed if it is enumerable', function() {
13+
it('GH-1603: should not allow constructors to be accessed (lookup via toString)', function() {
14+
expectTemplate('{{lookup (lookup this (list "constructor")) "name"}}')
15+
.withInput({})
16+
.withHelper('list', function(element) {
17+
return [element];
18+
})
19+
.toCompileTo('');
20+
});
21+
22+
23+
it('should allow the "constructor" property to be accessed if it is enumerable', function() {
924
shouldCompileTo('{{constructor.name}}', {'constructor': {
1025
'name': 'here we go'
1126
}}, 'here we go');
@@ -14,6 +29,13 @@ describe('security issues', function() {
1429
}}, 'here we go');
1530
});
1631

32+
it('should allow the "constructor" property to be accessed if it is enumerable', function() {
33+
shouldCompileTo('{{lookup (lookup this "constructor") "name"}}', {'constructor': {
34+
'name': 'here we go'
35+
}}, 'here we go');
36+
});
37+
38+
1739
it('should allow prototype properties that are not constructors', function() {
1840
function TestClass() {
1941
}

0 commit comments

Comments
 (0)