Added addon to suppress the sending of 502 Bad Gateway response… (#4299)

* WIP: Added option to suppress the sending of 502 Bad Gateway responses if the server is not responding

* Revert "WIP: Added option to suppress the sending of 502 Bad Gateway responses if the server is not responding"

This reverts commit 21b74f38b7ddeb63c5070cb4ca4928d3c37d12fe.

* Added addon which suppresses the bad gateway error messages sent by mitmproxy

* fix type annotation

Co-authored-by: Maximilian Hils <github@maximilianhils.com>
This commit is contained in:
anneborcherding 2020-11-20 09:15:12 +01:00 committed by GitHub
parent 5b6d75614e
commit 97bf522165
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,16 @@
"""
This script suppresses the 502 Bad Gateway messages, mitmproxy sends if the server is not responsing correctly.
For example, this functionality can be helpful if mitmproxy is used in between a web scanner and a web application.
Without this script, if the web application under test crashes, mitmproxy will send 502 Bad Gateway responses.
These responses are irritating the web application scanner since they obfuscate the actual problem.
"""
from mitmproxy import http
from mitmproxy.exceptions import HttpSyntaxException
def error(self, flow: http.HTTPFlow):
"""Kills the flow if it has an error different to HTTPSyntaxException.
Sometimes, web scanners generate malformed HTTP syntax on purpose and we do not want to kill these requests.
"""
if flow.error is not None and not isinstance(flow.error, HttpSyntaxException):
flow.kill()