diff options
| -rw-r--r-- | .travis.yml | 2 | ||||
| -rw-r--r-- | docs/src/content/howto-transparent.md | 2 | ||||
| -rw-r--r-- | examples/addons/commands-paths.py | 6 | ||||
| -rw-r--r-- | examples/complex/sslstrip.py | 4 | ||||
| -rwxr-xr-x | examples/complex/xss_scanner.py | 2 | ||||
| -rw-r--r-- | mitmproxy/addons/session.py | 4 | ||||
| -rw-r--r-- | mitmproxy/contentviews/css.py | 2 | ||||
| -rw-r--r-- | mitmproxy/contentviews/javascript.py | 4 | ||||
| -rw-r--r-- | mitmproxy/contentviews/xml_html.py | 2 | ||||
| -rw-r--r-- | mitmproxy/contrib/wbxml/ASCommandResponse.py | 5 | ||||
| -rw-r--r-- | mitmproxy/net/check.py | 2 | ||||
| -rw-r--r-- | mitmproxy/platform/pf.py | 2 | ||||
| -rw-r--r-- | mitmproxy/platform/windows.py | 2 | ||||
| -rw-r--r-- | mitmproxy/tools/console/help.py | 6 | ||||
| -rw-r--r-- | mitmproxy/tools/web/app.py | 2 | ||||
| -rw-r--r-- | mitmproxy/utils/strutils.py | 4 | ||||
| -rw-r--r-- | test/bench/benchmark.py | 3 | ||||
| -rw-r--r-- | test/mitmproxy/addons/test_session.py | 3 | ||||
| -rw-r--r-- | test/mitmproxy/coretypes/test_basethread.py | 2 | ||||
| -rw-r--r-- | test/mitmproxy/net/http/test_cookies.py | 4 | ||||
| -rw-r--r-- | test/mitmproxy/net/test_tcp.py | 2 | ||||
| -rw-r--r-- | web/src/js/ducks/ui/keyboard.js | 2 | 
22 files changed, 34 insertions, 33 deletions
| diff --git a/.travis.yml b/.travis.yml index dca567bf..20afc279 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,3 @@ -sudo: false  language: python  branches: @@ -34,7 +33,6 @@ matrix:      - python: 3.7        env: TOXENV=py37        dist: xenial -      sudo: true # required workaround for https://github.com/travis-ci/travis-ci/issues/9815      - language: node_js        node_js: "node"        before_install: diff --git a/docs/src/content/howto-transparent.md b/docs/src/content/howto-transparent.md index ae36f579..9be1e2f8 100644 --- a/docs/src/content/howto-transparent.md +++ b/docs/src/content/howto-transparent.md @@ -124,7 +124,7 @@ doas pfctl -e  You probably want a command like this:  {{< highlight bash  >}} -mitmproxy --mode transparent --showhost +mitmproxy --mode transparent --listen-host 127.0.0.1 --showhost  {{< / highlight >}}  The `--mode transparent` option turns on transparent mode, and the `--showhost` argument tells diff --git a/examples/addons/commands-paths.py b/examples/addons/commands-paths.py index f37a0fbc..4d9535b9 100644 --- a/examples/addons/commands-paths.py +++ b/examples/addons/commands-paths.py @@ -20,9 +20,9 @@ class MyAddon:          for f in flows:              totals[f.request.host] = totals.setdefault(f.request.host, 0) + 1 -        fp = open(path, "w+") -        for cnt, dom in sorted([(v, k) for (k, v) in totals.items()]): -            fp.write("%s: %s\n" % (cnt, dom)) +        with open(path, "w+") as fp: +            for cnt, dom in sorted([(v, k) for (k, v) in totals.items()]): +                fp.write("%s: %s\n" % (cnt, dom))          ctx.log.alert("done") diff --git a/examples/complex/sslstrip.py b/examples/complex/sslstrip.py index c862536f..69b9ea9e 100644 --- a/examples/complex/sslstrip.py +++ b/examples/complex/sslstrip.py @@ -38,7 +38,7 @@ def response(flow: http.HTTPFlow) -> None:      flow.response.content = flow.response.content.replace(b'https://', b'http://')      # strip meta tag upgrade-insecure-requests in response body -    csp_meta_tag_pattern = b'<meta.*http-equiv=["\']Content-Security-Policy[\'"].*upgrade-insecure-requests.*?>' +    csp_meta_tag_pattern = br'<meta.*http-equiv=["\']Content-Security-Policy[\'"].*upgrade-insecure-requests.*?>'      flow.response.content = re.sub(csp_meta_tag_pattern, b'', flow.response.content, flags=re.IGNORECASE)      # strip links in 'Location' header @@ -52,7 +52,7 @@ def response(flow: http.HTTPFlow) -> None:      # strip upgrade-insecure-requests in Content-Security-Policy header      if re.search('upgrade-insecure-requests', flow.response.headers.get('Content-Security-Policy', ''), flags=re.IGNORECASE):          csp = flow.response.headers['Content-Security-Policy'] -        flow.response.headers['Content-Security-Policy'] = re.sub('upgrade-insecure-requests[;\s]*', '', csp, flags=re.IGNORECASE) +        flow.response.headers['Content-Security-Policy'] = re.sub(r'upgrade-insecure-requests[;\s]*', '', csp, flags=re.IGNORECASE)      # strip secure flag from 'Set-Cookie' headers      cookies = flow.response.headers.get_all('Set-Cookie') diff --git a/examples/complex/xss_scanner.py b/examples/complex/xss_scanner.py index cdaaf478..97e94ed4 100755 --- a/examples/complex/xss_scanner.py +++ b/examples/complex/xss_scanner.py @@ -1,4 +1,4 @@ -""" +r"""   __   __ _____ _____     _____   \ \ / // ____/ ____|   / ____| diff --git a/mitmproxy/addons/session.py b/mitmproxy/addons/session.py index 63e382ec..f9073c3e 100644 --- a/mitmproxy/addons/session.py +++ b/mitmproxy/addons/session.py @@ -87,8 +87,8 @@ class SessionDB:      def _create_session(self):          script_path = pkg_data.path("io/sql/session_create.sql") -        qry = open(script_path, 'r').read() -        self.con.executescript(qry) +        with open(script_path, 'r') as qry: +            self.con.executescript(qry.read())          self.con.commit()      @staticmethod diff --git a/mitmproxy/contentviews/css.py b/mitmproxy/contentviews/css.py index cbe8ce62..44b33761 100644 --- a/mitmproxy/contentviews/css.py +++ b/mitmproxy/contentviews/css.py @@ -16,7 +16,7 @@ A custom CSS prettifier. Compared to other prettifiers, its main features are:  CSS_SPECIAL_AREAS = (      "'" + strutils.SINGLELINE_CONTENT + strutils.NO_ESCAPE + "'",      '"' + strutils.SINGLELINE_CONTENT + strutils.NO_ESCAPE + '"', -    r"/\*" + strutils.MULTILINE_CONTENT + "\*/", +    r"/\*" + strutils.MULTILINE_CONTENT + r"\*/",      "//" + strutils.SINGLELINE_CONTENT + "$"  )  CSS_SPECIAL_CHARS = "{};:" diff --git a/mitmproxy/contentviews/javascript.py b/mitmproxy/contentviews/javascript.py index 1440ea5d..b5f09150 100644 --- a/mitmproxy/contentviews/javascript.py +++ b/mitmproxy/contentviews/javascript.py @@ -10,9 +10,9 @@ SPECIAL_AREAS = (      r"'" + strutils.MULTILINE_CONTENT_LINE_CONTINUATION + strutils.NO_ESCAPE + "'",      r'"' + strutils.MULTILINE_CONTENT_LINE_CONTINUATION + strutils.NO_ESCAPE + '"',      r'`' + strutils.MULTILINE_CONTENT + strutils.NO_ESCAPE + '`', -    r"/\*" + strutils.MULTILINE_CONTENT + "\*/", +    r"/\*" + strutils.MULTILINE_CONTENT + r"\*/",      r"//" + strutils.SINGLELINE_CONTENT + "$", -    r"for\(" + strutils.SINGLELINE_CONTENT + "\)", +    r"for\(" + strutils.SINGLELINE_CONTENT + r"\)",  ) diff --git a/mitmproxy/contentviews/xml_html.py b/mitmproxy/contentviews/xml_html.py index 658fbcd7..00a62a15 100644 --- a/mitmproxy/contentviews/xml_html.py +++ b/mitmproxy/contentviews/xml_html.py @@ -18,7 +18,7 @@ The implementation is split into two main parts: tokenization and formatting of  """  # http://www.xml.com/pub/a/2001/07/25/namingparts.html - this is close enough for what we do. -REGEX_TAG = re.compile("[a-zA-Z0-9._:\-]+(?!=)") +REGEX_TAG = re.compile(r"[a-zA-Z0-9._:\-]+(?!=)")  # https://www.w3.org/TR/html5/syntax.html#void-elements  HTML_VOID_ELEMENTS = {      "area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", diff --git a/mitmproxy/contrib/wbxml/ASCommandResponse.py b/mitmproxy/contrib/wbxml/ASCommandResponse.py index 2d60eb2d..34755cbe 100644 --- a/mitmproxy/contrib/wbxml/ASCommandResponse.py +++ b/mitmproxy/contrib/wbxml/ASCommandResponse.py @@ -63,8 +63,9 @@ if __name__ == "__main__":  	listOfSamples = os.listdir(samplesDir)  	for filename in listOfSamples: -		byteWBXML = open(samplesDir + os.sep + filename, "rb").read() -		 +		with open(samplesDir + os.sep + filename, "rb") as f: +			byteWBXML = f.read() +  		logging.info("-"*100)  		logging.info(filename)  		logging.info("-"*100) diff --git a/mitmproxy/net/check.py b/mitmproxy/net/check.py index aaea851f..a19ad6fe 100644 --- a/mitmproxy/net/check.py +++ b/mitmproxy/net/check.py @@ -2,7 +2,7 @@ import ipaddress  import re  # Allow underscore in host name -_label_valid = re.compile(b"(?!-)[A-Z\d\-_]{1,63}(?<!-)$", re.IGNORECASE) +_label_valid = re.compile(br"(?!-)[A-Z\d\-_]{1,63}(?<!-)$", re.IGNORECASE)  def is_valid_host(host: bytes) -> bool: diff --git a/mitmproxy/platform/pf.py b/mitmproxy/platform/pf.py index bb5eb515..5e22ec31 100644 --- a/mitmproxy/platform/pf.py +++ b/mitmproxy/platform/pf.py @@ -11,7 +11,7 @@ def lookup(address, port, s):      """      # We may get an ipv4-mapped ipv6 address here, e.g. ::ffff:127.0.0.1.      # Those still appear as "127.0.0.1" in the table, so we need to strip the prefix. -    address = re.sub("^::ffff:(?=\d+.\d+.\d+.\d+$)", "", address) +    address = re.sub(r"^::ffff:(?=\d+.\d+.\d+.\d+$)", "", address)      s = s.decode()      spec = "%s:%s" % (address, port)      for i in s.split("\n"): diff --git a/mitmproxy/platform/windows.py b/mitmproxy/platform/windows.py index b849afa5..cb0a7096 100644 --- a/mitmproxy/platform/windows.py +++ b/mitmproxy/platform/windows.py @@ -58,7 +58,7 @@ class Resolver:      def original_addr(self, csock: socket.socket):          ip, port = csock.getpeername()[:2] -        ip = re.sub("^::ffff:(?=\d+.\d+.\d+.\d+$)", "", ip) +        ip = re.sub(r"^::ffff:(?=\d+.\d+.\d+.\d+$)", "", ip)          ip = ip.split("%", 1)[0]          with self.lock:              try: diff --git a/mitmproxy/tools/console/help.py b/mitmproxy/tools/console/help.py index 1b4b9ac6..fb4e0051 100644 --- a/mitmproxy/tools/console/help.py +++ b/mitmproxy/tools/console/help.py @@ -91,9 +91,9 @@ class HelpView(tabs.Tabs, layoutwidget.LayoutWidget):              )          )          examples = [ -            ("google\.com", "Url containing \"google.com"), -            ("~q ~b test", "Requests where body contains \"test\""), -            ("!(~q & ~t \"text/html\")", "Anything but requests with a text/html content type."), +            (r"google\.com", r"Url containing \"google.com"), +            ("~q ~b test", r"Requests where body contains \"test\""), +            (r"!(~q & ~t \"text/html\")", "Anything but requests with a text/html content type."),          ]          text.extend(              common.format_keyvals(examples, indent=4) diff --git a/mitmproxy/tools/web/app.py b/mitmproxy/tools/web/app.py index b72e0d77..6e6b6223 100644 --- a/mitmproxy/tools/web/app.py +++ b/mitmproxy/tools/web/app.py @@ -370,7 +370,7 @@ class FlowContent(RequestHandler):          original_cd = message.headers.get("Content-Disposition", None)          filename = None          if original_cd: -            filename = re.search('filename=([-\w" .()]+)', original_cd) +            filename = re.search(r'filename=([-\w" .()]+)', original_cd)              if filename:                  filename = filename.group(1)          if not filename: diff --git a/mitmproxy/utils/strutils.py b/mitmproxy/utils/strutils.py index 71d1c54c..388c765f 100644 --- a/mitmproxy/utils/strutils.py +++ b/mitmproxy/utils/strutils.py @@ -169,7 +169,7 @@ def split_special_areas(      >>> split_special_areas(      >>>     "test /* don't modify me */ foo", -    >>>     [r"/\*[\s\S]*?\*/"])  # (regex matching comments) +    >>>     [r"/\\*[\\s\\S]*?\\*/"])  # (regex matching comments)      ["test ", "/* don't modify me */", " foo"]      "".join(split_special_areas(x, ...)) == x always holds true. @@ -201,7 +201,7 @@ def escape_special_areas(      >>> x = escape_special_areas(x, "{", ["'" + SINGLELINE_CONTENT + "'"])      >>> print(x)      if (true) { console.log('�}'); } -    >>> x = re.sub(r"\s*{\s*", " {\n    ", x) +    >>> x = re.sub(r"\\s*{\\s*", " {\n    ", x)      >>> x = unescape_special_areas(x)      >>> print(x)      if (true) { diff --git a/test/bench/benchmark.py b/test/bench/benchmark.py index 84ec6005..076ad6c9 100644 --- a/test/bench/benchmark.py +++ b/test/bench/benchmark.py @@ -31,7 +31,8 @@ class Benchmark:              stdout=asyncio.subprocess.PIPE          )          stdout, _ = await traf.communicate() -        open(ctx.options.benchmark_save_path + ".bench", mode="wb").write(stdout) +        with open(ctx.options.benchmark_save_path + ".bench", mode="wb") as f: +            f.write(stdout)          ctx.log.error("Proxy saw %s requests, %s responses" % (self.reqs, self.resps))          ctx.log.error(stdout.decode("ascii"))          backend.kill() diff --git a/test/mitmproxy/addons/test_session.py b/test/mitmproxy/addons/test_session.py index 20feb69d..97351426 100644 --- a/test/mitmproxy/addons/test_session.py +++ b/test/mitmproxy/addons/test_session.py @@ -68,7 +68,8 @@ class TestSession:              os.remove(path)          con = sqlite3.connect(path)          script_path = pkg_data.path("io/sql/session_create.sql") -        qry = open(script_path, 'r').read() +        with open(script_path) as f: +            qry = f.read()          with con:              con.executescript(qry)              blob = b'blob_of_data' diff --git a/test/mitmproxy/coretypes/test_basethread.py b/test/mitmproxy/coretypes/test_basethread.py index 4a383fea..6b0ae154 100644 --- a/test/mitmproxy/coretypes/test_basethread.py +++ b/test/mitmproxy/coretypes/test_basethread.py @@ -4,4 +4,4 @@ from mitmproxy.coretypes import basethread  def test_basethread():      t = basethread.BaseThread('foobar') -    assert re.match('foobar - age: \d+s', t._threadinfo()) +    assert re.match(r'foobar - age: \d+s', t._threadinfo()) diff --git a/test/mitmproxy/net/http/test_cookies.py b/test/mitmproxy/net/http/test_cookies.py index 74233cca..06cfe1d3 100644 --- a/test/mitmproxy/net/http/test_cookies.py +++ b/test/mitmproxy/net/http/test_cookies.py @@ -27,7 +27,7 @@ cookie_pairs = [          [["one", "uno"], ["two", "due"]]      ],      [ -        'one="uno"; two="\due"', +        'one="uno"; two="\\due"',          [["one", "uno"], ["two", "due"]]      ],      [ @@ -70,7 +70,7 @@ def test_read_key():  def test_read_quoted_string():      tokens = [          [('"foo" x', 0), ("foo", 5)], -        [('"f\oo" x', 0), ("foo", 6)], +        [('"f\\oo" x', 0), ("foo", 6)],          [(r'"f\\o" x', 0), (r"f\o", 6)],          [(r'"f\\" x', 0), (r"f" + '\\', 5)],          [('"fo\\\"" x', 0), ("fo\"", 6)], diff --git a/test/mitmproxy/net/test_tcp.py b/test/mitmproxy/net/test_tcp.py index b6bb7cc1..22a306dc 100644 --- a/test/mitmproxy/net/test_tcp.py +++ b/test/mitmproxy/net/test_tcp.py @@ -102,7 +102,7 @@ class TestServerBind(tservers.ServerTestBase):              # We may get an ipv4-mapped ipv6 address here, e.g. ::ffff:127.0.0.1.              # Those still appear as "127.0.0.1" in the table, so we need to strip the prefix.              peername = self.connection.getpeername() -            address = re.sub("^::ffff:(?=\d+.\d+.\d+.\d+$)", "", peername[0]) +            address = re.sub(r"^::ffff:(?=\d+.\d+.\d+.\d+$)", "", peername[0])              port = peername[1]              self.wfile.write(str((address, port)).encode()) diff --git a/web/src/js/ducks/ui/keyboard.js b/web/src/js/ducks/ui/keyboard.js index ed4dbba5..007d24db 100644 --- a/web/src/js/ducks/ui/keyboard.js +++ b/web/src/js/ducks/ui/keyboard.js @@ -6,7 +6,7 @@ import * as modalActions from "./modal"  export function onKeyDown(e) {      //console.debug("onKeyDown", e) -    if (e.ctrlKey) { +    if (e.ctrlKey || e.metaKey) {          return () => {          }      } | 
