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

Fix URL parameter encoding #102

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = apig-wsgi
version = 2.4.0
version = 2.4.1
waderobson marked this conversation as resolved.
Show resolved Hide resolved
description = Wrap a WSGI application in an AWS Lambda handler function for running on API Gateway or an ALB.
long_description = file: README.rst, HISTORY.rst
long_description_content_type = text/x-rst
Expand Down
5 changes: 3 additions & 2 deletions src/apig_wsgi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
from base64 import b64decode, b64encode
from io import BytesIO
from urllib.parse import urlencode
from urllib.parse import unquote, urlencode

__all__ = ("make_lambda_handler",)

Expand Down Expand Up @@ -55,7 +55,8 @@ def get_environ(event, binary_support):
else:
body = body.encode("utf-8")
params = event.get("queryStringParameters") or {}

# decoding first to prevent double encoding
params = {k: unquote(v) for k, v in params.items()}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're only unquoting values - did you verify the issue doesn't exist in keys?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was that you would hopefully never have an application that has keys like that :). Probably not a safe assumption though.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A URL like example.com/?+123 should have a key with an empty string as the value

environ = {
"CONTENT_LENGTH": str(len(body)),
"HTTP": "on",
Expand Down
8 changes: 8 additions & 0 deletions tests/test_apig_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,14 @@ def test_querystring_one(simple_app):
assert simple_app.environ["QUERY_STRING"] == "foo=bar"


def test_querystring_decode_first(simple_app):
event = make_event(qs_params={"foo": "2018-06-13%3A07%3A44"})

simple_app.handler(event, None)

assert simple_app.environ["QUERY_STRING"] == "foo=2018-06-13%3A07%3A44"


def test_plain_header(simple_app):
event = make_event(headers={"Test-Header": "foobar"})

Expand Down