From dde27ba2477aa21c683129bf646e429c41f6bbd6 Mon Sep 17 00:00:00 2001 From: Jan Peter Stotz Date: Wed, 4 Nov 2020 14:20:01 +0100 Subject: [PATCH 1/2] asgiapp.py: fix query parameters --- CHANGELOG.rst | 1 + mitmproxy/addons/asgiapp.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 39fc4cc22..a5e45c264 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,7 @@ Release History Unreleased: mitmproxy next ========================== +* Fix query parameters in asgiapp addon (@jpstotz) * --- TODO: add new PRs above this line --- * ... and various other fixes, documentation improvements, dependency version bumps, etc. diff --git a/mitmproxy/addons/asgiapp.py b/mitmproxy/addons/asgiapp.py index ac4f935c8..5edb6ac84 100644 --- a/mitmproxy/addons/asgiapp.py +++ b/mitmproxy/addons/asgiapp.py @@ -55,7 +55,7 @@ def make_scope(flow: http.HTTPFlow) -> dict: # (byte string) – URL portion after the ?, percent-encoded. query_string: bytes if len(quoted_path) > 1: - query_string = quoted_path[1].encode() + query_string = urllib.parse.unquote(quoted_path[1]).encode() else: query_string = b"" From 66322c57e11aabc68d629e2c85914ceecf6bea12 Mon Sep 17 00:00:00 2001 From: Jan Peter Stotz Date: Fri, 6 Nov 2020 11:32:19 +0100 Subject: [PATCH 2/2] unit test for issue #4270 added --- test/mitmproxy/addons/test_asgiapp.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/test/mitmproxy/addons/test_asgiapp.py b/test/mitmproxy/addons/test_asgiapp.py index 5031e2c64..c5cadebc3 100644 --- a/test/mitmproxy/addons/test_asgiapp.py +++ b/test/mitmproxy/addons/test_asgiapp.py @@ -1,4 +1,7 @@ +import json + import flask +from flask import request from .. import tservers from mitmproxy.addons import asgiapp @@ -11,6 +14,14 @@ def hello(): return "testapp" +@tapp.route("/parameters") +def request_check(): + args = {} + for k in request.args.keys(): + args[k] = request.args[k] + return json.dumps(args) + + @tapp.route("/error") def error(): raise ValueError("An exception...") @@ -38,6 +49,12 @@ class TestApp(tservers.HTTPProxyTest): ret = p.request("get:'http://testapp/'") assert b"testapp" in ret.content + def test_parameters(self): + p = self.pathoc() + with p.connect(): + ret = p.request("get:'http://testapp/parameters?param1=1¶m2=2'") + assert b'{"param1": "1", "param2": "2"}' == ret.data.content + def test_app_err(self): p = self.pathoc() with p.connect(): @@ -50,4 +67,4 @@ class TestApp(tservers.HTTPProxyTest): with p.connect(): ret = p.request("get:'http://noresponseapp/'") assert ret.status_code == 500 - assert b"ASGI Error" in ret.content \ No newline at end of file + assert b"ASGI Error" in ret.content