fastify / aws-lambda-fastify

Insipired by aws-serverless-express to work with Fastify with inject functionality.
MIT License
498 stars 32 forks source link

Incorrect splitting of query parameters parameters containing literal commas #202

Closed jmalins closed 3 months ago

jmalins commented 6 months ago

The current query string translation logic doesn't distinguish between repeated query string values (i.e. &key=a&key=b) and values that contain URL encoded literal commas (i.e. &key=a%2Cb). The former should map to a fastify array value, the latter should not. It appears the API GW V2.0 event format has this same hazard.

The two cases could be distinguished by parsing the rawQueryString value (or for performance reasons, doing this only when a potential split is detected).

https://github.com/fastify/aws-lambda-fastify/blob/2e9387bfc8172be360c1bac997db216f7535d7fa/index.js#L65

adrai commented 6 months ago

Feel free to propose a PR.

jmalins commented 6 months ago

Thanks, will do. I have a workaround for now, but expect one in the next few days.

mouhannad-sh commented 3 months ago

Hi @jmalins can you please share your workaround ? I'm facing the same issue with commas

mouhannad-sh commented 3 months ago

I'm not sure if this is an intended behavior but I realised that the query string translation is mutating the original event argument passed to the lambda. For example if you pass &key=a%2Cb : When logging request.awsLambda.event you will get

{key: ["a","b"]}

even though the original event passed from API gateway is:

{"key": "a,b"}

This was confusing in our case because it made my team doubt that API gateway itself was transforming the query

I submitted a PR to address this behavior ( within the scope of the querystring ). and added a new option to allow users to opt-out from the current behaviour without causing any breaking changes for existing users

adrai commented 3 months ago

related to https://github.com/fastify/aws-lambda-fastify/issues/125 @maxkre96