Skip to content

Querystrings that have percent encodings get double encoded #99

@heathprovost

Description

@heathprovost

Before I begin I do not have much experience with Rust or the details of its various packages, but I did try to research this before posting it.

Problem: Whenever a url that contains a querystring with percent encoded values is passed through the adapter, it gets double encoded because (I think) the public function Url.query(&self) -> Option<&str> automatically applies percent encoding to the Url's existing querystring. The now double-percent-encoded querystring is applied to the new Url that is passed to .set_query() here: https://github.com/awslabs/aws-lambda-web-adapter/blob/main/src/lib.rs#L236

Since this adapter operates on values as they are passed to a server, generally any percent encoded that is required should already have been applied, so doing any encoding here (imo) is an error. I believe the correct behavior would be to always pass the querystring through unmolested. Alternately the value returned by .query() could be urldecoded before passing it through to set_query()

Here is an example of a url that triggers this issue:

https://test.com/?originalQueryString=%3FshowAll%3Dtrue

and this is the same url after passing through the adapter:

https://test.com/?originalQueryString=%25253FshowAll%25253Dtrue

I did a very amateurish fix for our own temporary use that looks like this, but I have no idea what I am doing with Rust so I expect you will have a better way to do this. That said, this does fix the problem for our purposes.

// ORG CODE
// app_url.set_query(parts.uri.query());

// NEW CODE
let querystring = parts.uri.query().unwrap_or_default();
let decoded_querystring = urlencoding::decode(querystring).unwrap_or_default();
app_url.set_query(Some(&decoded_querystring));

Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions