Skip to content

Query Param Silently Remove param query value if it is over 1000 #5878

Description

@ItsRLuo

Issue

The issue here is that if I have a really long query param(over 1000) ie. test?ids[]=1&ids[]=2..., it will truncate the value after length over 1000. This is because the qs library has a default parameterLimit of 1000 which then it won't parse any more value after. It seems in express body parser, this issue also exists but it returns an error if it is over a limit. https://github.com/expressjs/body-parser#parameterlimit
image

I know you can override the default query parser with my own, however I think this is very dangerous because the api shouldn't silently return incorrect value without warning. This issue is also coming from 2 layer of library deep so it is not easy to figure out for user of expressjs in my opinion.

Fix

  1. it should either return an error(similar to body parser), because I think this shouldn't silently remove value without alerting the engineer

  2. Alternatively we should set the parameterLimit limit to infinite(in qs options), this way if the user want to change the limit, they can knowingly change it, the users who are not aware of this won't be affected.

I can help with the PR if the above makes sense.

Activity

  1. added a commit that references this issue on Sep 3, 2024
    02a39de
  2. Mouri-P commented on Sep 3, 2024

    @Mouri-P

    I think the exported query parse middleware should allow an overwrite of req.query

      return function query(req, res, next){
        var val = parseUrl(req).query;
        req.query = queryparse(val, opts);
    
        next();
      };

    instead of

      return function query(req, res, next){
        if (!req.query) {
          var val = parseUrl(req).query;
          req.query = queryparse(val, opts);
        }
    
        next();
      };

    so that the users can do

    app.use(express.query({ parameterLimit: 10000 }));

    A quick workaround for this is

    app.use(function (req, res, next) {
      (req.query = undefined), next();
    }, express.query({ parameterLimit: 10000 }));
  3. ItsRLuo commented on Sep 5, 2024

    @ItsRLuo
    Author

    oh nice fix, that would work for my case, although I guess my main concern is still on that it silently removes query param if someone is not aware what is happening.

  4. Mouri-P commented on Sep 6, 2024

    @Mouri-P

    While I agree that this could be problematic for an unsuspecting user, throwing warnings whenever default values are used might not be the best solution, as it could lead to noise. Better documentation on these default behaviors would help clarify what’s happening.

    Moreover, passing 1000 elements as query parameters is not a widely used or recommended practice. Most web servers and browsers have a maximum URL length (typically around 2,000 characters), and sending a large number of elements in the query string can exceed this limit. It also makes URLs harder to read and maintain, and can expose sensitive data in server logs and browser history.

    For such large datasets, using a POST request with a JSON body is generally preferred.

    @ItsRLuo Your thoughts?

  5. ItsRLuo commented on Sep 9, 2024

    @ItsRLuo
    Author

    Those are very good best practices, I do still think it make sense to error or at least not remove values. A example is if you have a query param that is less than 1000 limit but with a large size, you will get a 414 URI Too Long error in your request, this makes so much sense to me so you can actually debug and figure out what was wrong instead of silently having a data integrity issue.

    However I do realized it is a rare case if at all you would want to have such large query parameter in your request, so I am fine with what you have to fix this issue as well!

  6. ljharb commented on Oct 25, 2024

    @ljharb

    fwiw I’d be willing to accept an option in qs that throws when exceeding the parameterLimit instead of silently truncating - then express could pass through both options so users can configure them as needed.

  7. wesleytodd commented on Oct 26, 2024

    @wesleytodd
    Member

    If this option was available we would make sure it is passed through and tested on this end.

    Also, for OP: I would consider not passing that many query params. There are more efficient ways to pass data to the server and what you describe of passing more than 1000 would for sure be an area you can improve your application by removing.

  8. ljharb commented on Oct 27, 2024

    @ljharb

    Filed ljharb/qs#515 in case anyone wants to discuss and implement it.

  9. wesleytodd commented on Jan 14, 2025

    @wesleytodd
    Member

    Are we just pending a bump on qs in express for this? Sorry, just trying to catch up on issues and this was in my backlog of notifications.

  10. ljharb commented on Jan 14, 2025

    @ljharb

    The option hasn't been released in qs just yet, although it's been merged. I'll see about cutting a release today.

  11. wesleytodd commented on Jan 14, 2025

    @wesleytodd
    Member

    No rush! Thanks for the update. I am hoping we can get all this wrapped up in the next week or two so we can cut an express release to call latest.

  12. ljharb commented on Jan 14, 2025

    @ljharb

    qs v6.14.0 has been released.

  13. IamLizu commented on Jan 15, 2025

    @IamLizu
    Member

    Awesome!

    I will get started on this side of the things here as well by this week.

    Edit: I will start with #5901 and see if I just need to bump the version or if there's anything else needed to be done.

  14. marked Query param #6348 as a duplicate of this issue on Feb 18, 2025
  15. added a commit that references this issue on Nov 21, 2025
    5105f41
  16. added a commit that references this issue on Feb 1, 2026
    d2e5945
  17. added a commit that references this issue on Feb 21, 2026
    8be258a
  18. added 4 commits that reference this issue on Mar 21, 2026
    b904621
    9c8ce1d
    a59c339
    3d78900
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions