-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
querystring module swallows __proto__
key
#5642
Comments
@WebReflection thanks for reporting this! It would appear we are already testing for similar edge cases in our tests, specifically for Adding
It looks like something weird going on with the test itself... but very well could be due to weirdness of overwriting the |
So atm this seems to be associated with the way that assigned properties on objects work in js. The So, AFAIK, we are kinda stuck on this platform being unable to parse There is definitely something subtle that I am missing here, and would love to see someone else sanity check this, but my current prognosis is that this is going to be a can't fix, simply due to the nature of the language 😭 |
Object.defineProperty wouldn't suffer any problem
|
@WebReflection it just struck me that I needed to be passing Womp. So now here is my next thought. We are now in a place where the only edge case where we would need to do this is with |
Possibly related, especially the discussion around performance: #728 |
You already do the hasOwnProperty check .... So: if key in obj &&
|
And that solves all edge cases. Sorry I'm typing with my phone, cheers
|
@WebReflection where are you seeing that afaik we use a key array lookup https://github.com/nodejs/node/blob/master/lib/querystring.js#L270 |
I haven't checked your implementation , I was giving a hint. You have
|
midnight here, so I won't probably answer any other question but you can check the PR I've just pushed and verified via the test suite provided by this repo. Hope it's clear what I meant when I've said |
Per nodejs#5642, using querystring.parse to parse 'a=b&__proto__=1' causes the `__proto__` to be swallowed and ignored. This works around the limitation by temporarily setting the prototype of the parsed obj to null during the parse, then setting it back before returning. Fixes: nodejs#5642
This commit safely allows querystring keys that are named the same as properties that are ordinarily inherited from Object.prototype such as __proto__. Additionally, this commit provides a bit of a speed improvement (~25% in the querystring-parse 'manypairs' benchmark) when there are many unique keys. Fixes: nodejs#5642 PR-URL: nodejs#6055 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
This commit safely allows querystring keys that are named the same as properties that are ordinarily inherited from Object.prototype such as __proto__. Additionally, this commit provides a bit of a speed improvement (~25% in the querystring-parse 'manypairs' benchmark) when there are many unique keys. Fixes: nodejs#5642 PR-URL: nodejs#6055 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
This commit safely allows querystring keys that are named the same as properties that are ordinarily inherited from Object.prototype such as __proto__. Additionally, this commit provides a bit of a speed improvement (~25% in the querystring-parse 'manypairs' benchmark) when there are many unique keys. Fixes: #5642 PR-URL: #6055 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
If a URL contains
__proto__=123
that has no meaning for any other server out there and it's handled like a regular string.However, the querystring module swallows the key, probably trying to set the string
"123"
as returned object prototype.Since every other key is set as
{configurable: true, writable: true, enumerable: true, value: decodedValue}
I think in the very specialkey in out && !hasOwnProperty.call(out, key)
case the returnedout
object should have properties set as such:This would grant consistency with any sort of possible dangerous key inherited, as setter or getter, through the
Object.prototype
.querystring
Best Regards
The text was updated successfully, but these errors were encountered: