-
Notifications
You must be signed in to change notification settings - Fork 560
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
Lambdas implementing RequestStreamHandler are double decoding query parameters (Jersey) #146
Comments
Using debugger I was able to track it down to the method: org.glassfish.jersey.server.spi.internal.ParameterValueHelper.getParameterValues It receives correct request “hello+world” and returns “hello world”. Link to source: |
Was able to fix the issue by adding public String test(@QueryParam("key") @Encoded String value) |
After trying out Given the string Using Without |
I've done some tests calling through the browser. The API Gateway endpoint hits a Lambda function (proxy integration) that simply dumps the event. This is what I see:
The issue seems to be that when a + is not URL encoded API Gateway itself removes it from the string. The framework never has a chance to see the character. I think API Gateway's behavior is correct. The encoding rules for form values, which include query string values, state that the + sign is used to encode a space " ". For this reason, when you send API Gateway a literal + in the value of a query string parameter, it decodes it as a space. Wikipedia, RFC. I'll start investigating the behavior of your second issue, where the "/" character is the only one that remains encoded when you ask Jersey for the |
Hey Stefano, I'm always encoding the query string that contains the Somewhere in the chain between API Gateway and Lambda, where multiple encoding/decoding may be happening before forwarding on, could it be possible that pure percent encoding/decoding is occurring in some places whereas in other places its using URLEncoder/URLDecoder which handles |
Here's an update on the second issue. You are calling API Gateway with the encoded value of
When you ask Jersey for the decoded value, it turns the I'll think this through and see if I can come up with a solution. It may be as simple as using Jersey's own encoder before setting the query string so that it is already encoded as Jersey expects it. |
Hey @boardthatpowder, any chance you can test with the |
release 1.1.1 is going out to maven central |
Scenario
Client > APi Gateway > Lambda.
When using
.
JerseyLambdaContainerHandler proxyStream(inputStream, outputStream, context)
in a RequestStreamHandler implementation, query params are de-coded a second time before passed to the appropriate JAX-RS controller. This causes issues with strings containing+
, which are encoded as%2B
, decoded once as+
, but then decoded a second time asExpected behavior
Passing
%2B
in a query parameter from a client should reach the JAX-RS controller as+
.Actual behavior
Passing
.
%2B
in a query parameter from a client reaches the JAX-RS controller asSteps to reproduce
Create an endpoint:
Proxy the JAX-RS with a streaming lambda:
Expose the lambda via API Gateway. Make a request to
GET /test?param=ab%2Bcd
.Full log output
The text was updated successfully, but these errors were encountered: