-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent access to other prototype properties #1594
Conversation
ab74b7f
to
4c034c8
Compare
98c4ca9
to
df180a0
Compare
@nknapp while I appreciate the vote of confidence, I think this PR is way beyond my knowledge of the subtleties of JavaScript 😱 One general comment: I think the PR description does a great job of justifying why is the change needed. I think it would be great if a similar description made its way into the comments in the code itself - I think future maintainers of this codebase (which might very well be you 😉) will appreciate it when they see this a year (or later) from now :). |
96df165
to
31f3343
Compare
Use map-objects (with `null`-prototype for some internal maps that are accessed by the compiled template code to prevent accidental access of Object prototype properties (this includes the "helpers"-object, "partials"-object and "knownHelpers") Added compile options: - allowNonHelperFunctionCall: default: true, if set to false, the template will not call functions with arguments) that are defined on the current context object. Lambdas (function calls without arguments) are still allowed. - propertyMustBeEnumerable a object (propertyName: boolean) of properties that must be enumerable in order to be resolved from the current context object. By default `__defineGetter__`, `__defineSetter__` , `__proto__` and `constructor` are forbidden (if not enumerable) and will return "undefined" instead of the actual property. Use `{ __defineGetter_: false }` to allow __defineGetter__ (not recomended).
- properties not configurable anymore - add more harmful properties to the list (push, pop, splice...)
31f3343
to
caacce4
Compare
The npm security advisories 755 and 1164 were both caused by access to the
constructor
property. The initial fix was circumvented in advisory (1164) by the use of__defineGetter__
and__defineSetter
.In order to prevent other attacks in the future, this PR restricts access to properties in two way:
allowNonHelperFunctionCall
is set tofalse
, any use of properties of the input object as function-calls with parameters is prohibited. Lambdas are still allowed.__defineGetter__
,__defineSetter
and__proto__
are only allowed if they are enumerable on their parent. The list is configurable through the compile-optionpropertyMustBeEnumerable
.The main question is: Which other properties should be restricted by default?
I don't want to cause trouble by creating unnecessary restrictions, but I also want to prevent other security leaks.