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

Double encoding of query #219

Open
karlismelderis opened this issue Mar 19, 2019 · 3 comments
Open

Double encoding of query #219

karlismelderis opened this issue Mar 19, 2019 · 3 comments
Labels

Comments

@karlismelderis
Copy link

seems that query is encoded one more time when hitting express.
I had to add this peace of code before passing event to module:

exports.handler = (event, context) => {
    Object.keys(event.queryStringParameters).forEach((key) => {
        // eslint-disable-next-line no-param-reassign
        event.queryStringParameters[key] = decodeURIComponent(event.queryStringParameters[key]);
    });
    awsServerlessExpress.proxy(server, event, context);
};
@brettstack brettstack added the v4 label May 10, 2019
@brettstack
Copy link
Collaborator

Thanks. I'll need to verify this and fix as part of v4.

@nabilfreeman
Copy link

Hi, just saw this. I think it's the same problem I described in #241 .

@karlismelderis were you using Application Load Balancer by any chance?

@jbt
Copy link

jbt commented Aug 21, 2019

I'd just like to chime in here and say I'm also running into this as an issue. In additional to the decoding, it's important to note that the + character has special behaviour in query strings - it decodes to a space character, but not if you use decodeURIComponent, so in the example above you'll still be getting + characters back when you shouldn't.

Here's the solution I've been using, which effectively rebuilds the whole URL and then parses it again using the querystring module:

const querystring = require('querystring');

exports.handler = (event, context) => {
  const qs = Object.keys(event.queryStringParameters).map(key => key + '=' + event.queryStringParameters[key]).join('&');
  event.queryStringParameters = querystring.parse(qs);

  ase.proxy(server, event, context);
};

That said, I'm pretty sure the behaviour of not decoding keys and values is a bug, both because of how it's inconsistent with API Gateway, and how it can't cope with certain characters (e.g. ?foo%25bar=baz apparently decodes as { foo: "" } which is obviously wrong) so perhaps this needs to be addressed at a higher level inside the ALB-Lambda handler itself rather than inside this module

@brettstack brettstack added the bug label Feb 1, 2021
fredericgermain added a commit to fredericgermain/serverless-express that referenced this issue Mar 25, 2021
fredericgermain added a commit to fredericgermain/serverless-express that referenced this issue Mar 25, 2021
github-actions bot pushed a commit that referenced this issue Jun 9, 2021
## [4.3.9](v4.3.8...v4.3.9) (2021-06-09)

### Bug Fixes

* auto-unescape query parameters on ALB ([#219](#219), [#241](#241)) ([#393](#393)) ([8cb4206](8cb4206))
OneDev0411 added a commit to OneDev0411/serverless-express that referenced this issue Mar 16, 2023
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

4 participants