aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUjjwal Verma <ujjwalverma1111@gmail.com>2017-02-10 01:26:06 +0530
committerMaximilian Hils <git@maximilianhils.com>2017-02-09 20:56:06 +0100
commitd6465b907f238f50c20c51304723260c9aaa61ab (patch)
treec70535fa648fc1f14e135412e23f60cd548ef13b
parent380ff50e57a56d2ff25f04350341ae013dcd2443 (diff)
downloadmitmproxy-d6465b907f238f50c20c51304723260c9aaa61ab.tar.gz
mitmproxy-d6465b907f238f50c20c51304723260c9aaa61ab.tar.bz2
mitmproxy-d6465b907f238f50c20c51304723260c9aaa61ab.zip
Closes #1580 Gives warning when explicit proxy configured in transparent mode (#1996)
-rw-r--r--mitmproxy/proxy/protocol/http.py15
-rw-r--r--test/mitmproxy/protocol/test_http1.py10
2 files changed, 21 insertions, 4 deletions
diff --git a/mitmproxy/proxy/protocol/http.py b/mitmproxy/proxy/protocol/http.py
index b70afe33..da9a8781 100644
--- a/mitmproxy/proxy/protocol/http.py
+++ b/mitmproxy/proxy/protocol/http.py
@@ -131,7 +131,7 @@ class HTTPMode(enum.Enum):
# At this point, we see only a subset of the proxy modes
MODE_REQUEST_FORMS = {
HTTPMode.regular: ("authority", "absolute"),
- HTTPMode.transparent: ("relative"),
+ HTTPMode.transparent: ("relative",),
HTTPMode.upstream: ("authority", "absolute"),
}
@@ -143,9 +143,16 @@ def validate_request_form(mode, request):
)
allowed_request_forms = MODE_REQUEST_FORMS[mode]
if request.first_line_format not in allowed_request_forms:
- err_message = "Invalid HTTP request form (expected: %s, got: %s)" % (
- " or ".join(allowed_request_forms), request.first_line_format
- )
+ if mode == HTTPMode.transparent:
+ err_message = (
+ "Mitmproxy received an {} request even though it is not running in regular mode. "
+ "This usually indicates a misconfiguration, please see "
+ "http://docs.mitmproxy.org/en/stable/modes.html for details."
+ ).format("HTTP CONNECT" if request.first_line_format == "authority" else "absolute-form")
+ else:
+ err_message = "Invalid HTTP request form (expected: %s, got: %s)" % (
+ " or ".join(allowed_request_forms), request.first_line_format
+ )
raise exceptions.HttpException(err_message)
diff --git a/test/mitmproxy/protocol/test_http1.py b/test/mitmproxy/protocol/test_http1.py
index cd937ada..44a9effa 100644
--- a/test/mitmproxy/protocol/test_http1.py
+++ b/test/mitmproxy/protocol/test_http1.py
@@ -30,6 +30,16 @@ class TestInvalidRequests(tservers.HTTPProxyTest):
assert b"Invalid HTTP request form" in r.content
+class TestProxyMisconfiguration(tservers.TransparentProxyTest):
+
+ def test_absolute_request(self):
+ p = self.pathoc()
+ with p.connect():
+ r = p.request("get:'http://localhost:%d/p/200'" % self.server.port)
+ assert r.status_code == 400
+ assert b"misconfiguration" in r.content
+
+
class TestExpectHeader(tservers.HTTPProxyTest):
def test_simple(self):