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
3 changes: 3 additions & 0 deletions lib/handlebars/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ export function template(templateSpec, env) {
}

if (resultIsAllowed(result, container.protoAccessControl, propertyName)) {
if (typeof result === 'function') {
return parent[propertyName]();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you use parent[propertyName]() instead of result()? Any specific reason?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't work with result(), complains that:

TypeError: String.prototype.trim called on null or undefined

I'm not 100% sure why, but as I understand result loses this context.

}
return result;
}
return undefined;
Expand Down
11 changes: 11 additions & 0 deletions spec/security.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,17 @@ describe('security issues', function() {
})
.toCompileTo('abc');
});

it('should call an allowed proto method', function() {
expectTemplate('{{aString.trim}}')
.withInput({ aString: ' abc ' })
.withRuntimeOptions({
allowedProtoMethods: {
trim: true
}
})
.toCompileTo('abc');
});
});

describe('control access to prototype non-methods via "allowedProtoProperties" and "allowProtoPropertiesByDefault', function() {
Expand Down