Bref: Query String encoding issues when using ALB

Created on 16 Sep 2019  路  5Comments  路  Source: brefphp/bref

When running API Gateway, query strings in the event object are automagically URL decoded but when using Application Load Balancer, they're not. This leads to a problem where the getQueryString function (here) ends up URL encoding ALB query strings twice. (more information can be found here)

Here's an example of what we get out when using these parameters ?single=value%20with%20spaces&multi[rise%20of%20planets]=hello%20world&multi[death%20of%20planets]=bye%20world running Laravel.

API Gateway
Screenshot 2019-09-16 at 15 20 48

Application Load Balancer
Screenshot 2019-09-16 at 15 20 39

From what I've found so far, there's no super clear way of figuring out if the invokation is from API Gateway or Application Load Balancer but what we could do is check the event and see if the API Gateway specific event properties are there or not and URL decode the result of the http_build_query once before returning it, if not from API Gateway. (event differences from SO)

bug help wanted

Most helpful comment

Should be fixed by #693

All 5 comments

I've temporarily solved this by overwriting the PhpFpm.php file before deploy where I wrap http_build_query in urldecode.

https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html

If the query parameters are URL-encoded, the load balancer does not decode them. You must decode them in your Lambda function.

So, unfortunately, we need to handle it in the lambda function runtime.

I've been using Lambda with Bref behind ALB quite a lot and I'm not sure why I've been oblivious to this issue.
Is there something specific my requests need in order to cause the problem? I use Laravel, is it relevant for the issue?
We have SPA sending lots of requests using axios and jquery and I never noticed anything regarding encoding. I'd like to better understand this problem in order to figure out if I might be a victim of it at some point

Should be fixed by #693

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tlfbrito picture tlfbrito  路  4Comments

spaceemotion picture spaceemotion  路  8Comments

tlfbrito picture tlfbrito  路  8Comments

t-geindre picture t-geindre  路  4Comments

Yalian picture Yalian  路  9Comments