Skip to content

Commit 85c8783

Browse files
committed
fix: prevent RCE through the "lookup"-helper
- The "lookup" helper could also be used to run a remote code execution by manipulating the template. The same check as for regular path queries now also is done in the "lookup"-helper
1 parent d97a045 commit 85c8783

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/handlebars/helpers/lookup.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
export default function(instance) {
22
instance.registerHelper('lookup', function(obj, field) {
3-
return obj && obj[field];
3+
if (!obj) {
4+
return obj;
5+
}
6+
if (field === 'constructor' && !obj.propertyIsEnumerable(field)) {
7+
return undefined;
8+
}
9+
return obj[field];
410
});
511
}

spec/security.js

+7
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ 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() {
44
shouldCompileTo('{{constructor.name}}', {}, '');
5+
shouldCompileTo('{{lookup (lookup this "constructor") "name"}}', {}, '');
56
});
67

78
it('should allow the "constructor" property to be accessed if it is enumerable', function() {
89
shouldCompileTo('{{constructor.name}}', {'constructor': {
910
'name': 'here we go'
1011
}}, 'here we go');
12+
shouldCompileTo('{{lookup (lookup this "constructor") "name"}}', {'constructor': {
13+
'name': 'here we go'
14+
}}, 'here we go');
1115
});
1216

1317
it('should allow prototype properties that are not constructors', function() {
@@ -23,6 +27,9 @@ describe('security issues', function() {
2327

2428
shouldCompileTo('{{#with this as |obj|}}{{obj.abc}}{{/with}}',
2529
new TestClass(), 'xyz');
30+
shouldCompileTo('{{#with this as |obj|}}{{lookup obj "abc"}}{{/with}}',
31+
new TestClass(), 'xyz');
32+
2633
});
2734
});
2835
});

0 commit comments

Comments
 (0)