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

Weird req.query behavior #4878

Closed
VladimirMikulic opened this issue Mar 29, 2022 · 2 comments
Closed

Weird req.query behavior #4878

VladimirMikulic opened this issue Mar 29, 2022 · 2 comments
Labels

Comments

@VladimirMikulic
Copy link

Hi! I recently encountered an interesting case of how query string shows up in req.query in my logs.

Normal call: https://some-api.com/?tags=tag1,tag2,tag3

{
  tags: "tag1,tag2,tag3"
}

Weird/potentially dangerous: https://some-api.com/?tags=tag1,tag2,tag3&tags[i]=tag4 <- notice this tags[i]=<value>

Here's how the req.query looks like:

{
  tags: ["tag1", "tag2", "tag3", { i: "tag" }]
}

I would expect tags to be a string just like in normal call.
It shouldn't suddenly turn to an array with strings and an object at the end.

@dougwilson
Copy link
Contributor

Hi @VladimirMikulic yes, this is the expected behavior. You can find that in our documentation about req.query (http://expressjs.com/en/api.html#req.query) and the query parser setting http://expressjs.com/en/api.html#app.settings.table

You can change the behavior with that above query parser setting. You likely want the simple parser rather than the extended parser. The main difference is that extended uses the qs module and simple uses the Node.js querystring module (both linked from our docs).

I hope that helps!

@VladimirMikulic
Copy link
Author

Thank you for a fast reply, @dougwilson! That makes sense.

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

No branches or pull requests

2 participants