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

feat: use Map rather than Object for internal result properties #57

Closed
wants to merge 2 commits into from

Conversation

shadowspawn
Copy link
Collaborator

This came out of discussion around potential for prototype pollution. Use a Map rather than Object internally. Convert to Object for returning to client.

See #32 (comment)

(Why not use Set for flags? Could, but a little easier to convert from Map to Object!)

Copy link
Collaborator

@bcoe bcoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this change, I think it would be worth adding a few unit tests that demonstrate that we're protected from a prototype pollution, here are some specific test cases added for yargs to address security issues:

yargs/yargs-parser#258
yargs/yargs-parser#234
https://github.com/yargs/y18n/blob/master/test/y18n-test.cjs#L356

flags: {},
values: {},
flags: new Map(),
values: new Map(),
Copy link
Member

@ljharb ljharb Feb 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These need to use SafeMap instead - and, then they don’t have to use the prototype primordials.

(If they don’t, then the ObjectFromEntries call isn’t safe, because of Map.prototype[Symbol.iterator])

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(@shadowspawn note, you can just import SafeMap from primordials).

@shadowspawn
Copy link
Collaborator Author

Thanks for feedback. I'll start again rather than leave this open, as it may be a couple of weeks before I have time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants