Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

bitwiseman
Copy link

@bitwiseman bitwiseman commented May 19, 2021

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 in strict mode.
@nknapp

Generally we like to see pull requests that

  • Please don't start pull requests for security issues. Instead, file a report at https://www.npmjs.com/advisories/report?package=handlebars
  • Maintain the existing code style
  • Are focused on a single change (i.e. avoid large refactoring or style adjustments in untouched code if not the primary goal of the pull request)
  • Have good commit messages
  • Have tests
  • Have the typings (lib/handlebars.d.ts) updated on every API change. If you need help, updating those, please mention that in the PR description.
  • Don't significantly decrease the current code coverage (see coverage/lcov-report/index.html)
  • Currently, the 4.x-branch contains the latest version. Please target that branch in the PR.

expectTemplate('{{constructor.name}}')
.withCompileOptions(compileOptions)
.withInput({})
.toThrow(TypeError);
Copy link
Author

@bitwiseman bitwiseman May 19, 2021

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);
Copy link
Author

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);
Copy link
Author

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:

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.

@batmat
Copy link

batmat commented May 25, 2021

@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 :-).
Thanks a lot for your hard work!

@bitwiseman
Copy link
Author

bitwiseman commented May 25, 2021

@ErisDS @Afanyiyu @kpdecker @lawnsea @wycats
Sorry for pinging you all but this is a security issue that it would be great to get backported sooner rather than later.

@jaylinski jaylinski self-assigned this Nov 23, 2021
@jaylinski jaylinski added the bug label Nov 23, 2021
@bitwiseman
Copy link
Author

@jaylinski
Hey, thanks for the label update. If there is anything I can do to make this PR merge sooner, please just say so.
@car-roll @batmat @jtnord may also want to be updated on this.

@jaylinski
Copy link
Member

jaylinski commented Dec 30, 2021

Memo to myself:

@nknapp
Copy link
Collaborator

nknapp commented Jan 7, 2022

@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...

@nknapp
Copy link
Collaborator

nknapp commented Jan 7, 2022

can you modify your PR, so that only f058970 is backported?

@windusayles
Copy link

@bitwiseman @nknapp do we need the modification you mentioned, f058970, in order to merge this fix?

@wycats
Copy link
Collaborator

wycats commented Aug 18, 2022

@windusayles yeah 👍

Can you update the PR to limit it to just f058970?

@jaylinski
Copy link
Member

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.

image

https://www.npmjs.com/package/handlebars?activeTab=versions

Also: v3.x is now marked as EOL in our security policy (35f0018).

@jaylinski jaylinski closed this Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants