-
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
Backport security fixes for #1736 #1751
Conversation
expectTemplate('{{constructor.name}}') | ||
.withCompileOptions(compileOptions) | ||
.withInput({}) | ||
.toThrow(TypeError); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was already the case in 3.x before this change and remains after this change currently. strict
mode resulted in a TypeError
when accessing constructor
, __proto__
, etc. We can fix this but it would require more changes and would not improve the security.
}, | ||
lookup: function(depths, name) { | ||
const len = depths.length; | ||
for (let i = 0; i < len; i++) { | ||
if (depths[i] && depths[i][name] != null) { | ||
let result = depths[i] && container.lookupProperty(depths[i], name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This covers compat mode.
@@ -69,12 +69,28 @@ export function template(templateSpec, env) { | |||
if (!(name in obj)) { | |||
throw new Exception('"' + name + '" not defined in ' + obj); | |||
} | |||
return obj[name]; | |||
return container.lookupProperty(obj, name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears strict
mode is already covered by the check in javascript-compiler.js
:
handlebars.js/lib/handlebars/compiler/javascript-compiler.js
Lines 16 to 19 in 16bd606
if (dangerousPropertyRegex.test(name)) { | |
const isOwnProperty = [ this.aliasable('Object.prototype.hasOwnProperty'), '.call(', parent, ',', JSON.stringify(name), ')']; | |
return ['(', isOwnProperty, '?', _actualLookup(), ' : undefined)']; | |
} |
However, the reason why this vulnerability appeared in 4.x was because that check was removed and this change was present. Better to make this change to make it completely clear.
@nknapp hello! Any chance you would be able to look into this some day soon? We are ready to help as need be, please let us know :-). |
@jaylinski |
Memo to myself:
|
@bitwiseman I think the compat-mode (f058970) part is worth backporting, but I wouldn't touch the part that is no real security issue in version 3. Changes in version 3 are only done on a strict "need to be there" basis, as far as I am concerned... |
can you modify your PR, so that only f058970 is backported? |
@bitwiseman @nknapp do we need the modification you mentioned, f058970, in order to merge this fix? |
@windusayles yeah 👍 Can you update the PR to limit it to just f058970? |
Closing since v3.0.8 only has a few thousand downloads a week. So most people moved on to the latest (and more secure) version. https://www.npmjs.com/package/handlebars?activeTab=versions Also: v3.x is now marked as EOL in our security policy (35f0018). |
I would not file a PR for this except that the security advisory has already been filed.
This PR addresses the vulnerability in
compat
mode and documents the lack of vulnerability instrict
mode.@nknapp
Generally we like to see pull requests that
4.x
-branch contains the latest version. Please target that branch in the PR.