Prevent prototype pollution chaining to code execution via _.template#4355
Merged
jdalton merged 3 commits intolodash:4.17.12-prefrom Jul 9, 2019
Merged
Conversation
... and not via its prototype, as that enables chaining a prototype pollution into arbitrary code execution.
Member
|
Ah, I thought the one raised by |
Contributor
Author
|
@jdalton Great, thanks for the quick response :) I adjusted the regexp to strip all |
jdalton
reviewed
Jul 8, 2019
lodash.js
Outdated
| ('sourceURL' in options | ||
| ? options.sourceURL | ||
| (hasOwnProperty.call(options, 'sourceURL') | ||
| ? options.sourceURL.replace(/[\r\n]/g, ' ') |
Member
There was a problem hiding this comment.
Can you coerce options.sourceURL to a string. Something like (options.sourceURL + '').replace would do.
Coerce sourceURL to string
Member
|
Awesome! Thank you so much @alexbrasetvik! Update: Published updated versions of |
kobelb
added a commit
to kobelb/lodash
that referenced
this pull request
Jul 9, 2019
Contributor
Author
|
Thanks for the quick turnaround! :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prototype pollution is a common problem for Javascript applications.
This paper (PDF-link) is a reasonably comprehensive resource on the subject. It demonstrates that the problem is quite ubiquitous, and how it can turn into an unauthenticated RCE in Ghost, where the attack chain starts with a prototype pollution vulnerability in lodash.merge. Handlebars is used as the code execution gadget, but as Ghost also uses _.template it could have targeted that as well.
Lodash has had multiple prototype pollution vulnerabilities, including recently.
If
_.templateis ever invoked after the prototype has been polluted, an attacker can execute any Javascript, assourceURLandvariableare looked up via anoptionsobject and injected into the Javascript that gets executed. If the caller is not passing those options (which is the most common usage), then the values from the potentially polluted prototype would be used instead. Here's the smallest possible POC:I initially reached out via npm security, and got the feedback that this is not considered an issue. (In the thread with NPM security I also provided examples of how to weaponise this against real applications instead of just the repl example. I can provide additional examples privately.)
I think it's worth fixing, as the fix is simple. Applications that are susceptible to prototype pollution will still need fixing, but at least the commonly used
_.templateshouldn't provide easy code execution.(I've signed the CLA.)