kwhitley / itty-router

A little router.
MIT License
1.71k stars 77 forks source link

Prototype properties in query #142

Closed DrLoopFall closed 1 year ago

DrLoopFall commented 1 year ago

Bug

URL ...?toString=value results in query { toString: [ <toString function>, "value" ] }.

Solutions

This would be a breaking change.

kwhitley commented 1 year ago

Testing this today...

a) Good catch! How did you even find this?? b) Not sure if we should fix it... because:

DrLoopFall commented 1 year ago

a) Good catch! How did you even find this??

Was checking Node's querystring.parse, and found that it returns an object with a null prototype.

params will fall under the same issue I suspect (and would cost more bytes to fix)

The params object already has a null prototype, match.groups is an object with a null prototype. For consistency, we can also make prototype of the fallback object null request.params = match.groups || { __proto: null }

I think the worse side effect of fixing it is that a thing that looks like an object (query, params, etc) actually fails to have the properties/methods of a real object.

Not fixing would result in objects having arrays instead of the expected object's properties/methods. e.g. req.toString() would throw error.


Here are a few query parser libraries behavior,


This bug is not much likely to cause security issues. If we want we can leave it as it is.