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

Usage of default-prototype Object for URL params results in parsing problems #282

Open
ThomasRinsma opened this issue Mar 16, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@ThomasRinsma
Copy link

Environment

Node v23.10.0, ufo version 1.5.4.

Reproduction

> ufo.getQuery("http://foo.com/?toString=a")
{ toString: [ [Function: toString], 'a' ] }

Describe the bug

The accumulator object used during query parsing (initialized here), is a regular JavaScript Object. This means that it all the default Object keys are valid keys:

> x = {};
{}
> x.<tab complete>
x.__proto__             x.constructor           x.hasOwnProperty        x.isPrototypeOf         x.propertyIsEnumerable
x.toLocaleString        x.toString              x.valueOf

As regular key-accessing is used, the prototype chain is followed, hence, the check here will not be undefined for those keys, and this assignment logic will be followed.

In other words, while there is a check for __proto__ and constructor to prevent prototype pollution (I presume), this does not solve the problem of accessing other keys in the object's prototype. A good solution would be to use Object.create(null) instead of {} to initialize object.

Additional context

No response

Logs

@ThomasRinsma ThomasRinsma added the bug Something isn't working label Mar 16, 2025
@pi0
Copy link
Member

pi0 commented Mar 17, 2025

Thanks for report. Feel free to open a PR. You can use this pattern to avoid perf penalty of null object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants