Skip to content

Commit

Permalink
Fix handlebars-lang#1748 where allowed prototype methods are not called
Browse files Browse the repository at this point in the history
  • Loading branch information
aalimovs authored and jaylinski committed Jul 25, 2023
1 parent 668c4fb commit 5cae846
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
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]();
}
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

0 comments on commit 5cae846

Please sign in to comment.