From b84a821fd88ab427b4548c99d6230bc5bfe7a496 Mon Sep 17 00:00:00 2001 From: Emanuele Micheletti Date: Tue, 12 Dec 2023 19:33:19 +0100 Subject: [PATCH] make url filters case-insensitive (#6493) fix #6329 --- CHANGELOG.md | 2 ++ mitmproxy/flowfilter.py | 1 + test/mitmproxy/addons/test_blocklist.py | 15 ++++++++------- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b47e55ff05..30713bb066 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ ([#6543](https://github.com/mitmproxy/mitmproxy/pull/6543), @mhils) * DNS resolution is now exempted from `--ignore-hosts` in WireGuard Mode. ([#6513](https://github.com/mitmproxy/mitmproxy/pull/6513), @dsphper) +* Fix case sensitivity of URL added to blocklist + ([#6493](https://github.com/mitmproxy/mitmproxy/pull/6493), @emanuele-em) * Fix a bug where logging was stopped prematurely during shutdown. ([#6541](https://github.com/mitmproxy/mitmproxy/pull/6541), @mhils) * For plaintext traffic, `--ignore-hosts` now also takes HTTP/1 host headers into account. diff --git a/mitmproxy/flowfilter.py b/mitmproxy/flowfilter.py index 52db22be03..840583f3d1 100644 --- a/mitmproxy/flowfilter.py +++ b/mitmproxy/flowfilter.py @@ -402,6 +402,7 @@ class FUrl(_Rex): code = "u" help = "URL" is_binary = False + flags = re.IGNORECASE # FUrl is special, because it can be "naked". diff --git a/test/mitmproxy/addons/test_blocklist.py b/test/mitmproxy/addons/test_blocklist.py index 9187443b28..b7c7e536d3 100644 --- a/test/mitmproxy/addons/test_blocklist.py +++ b/test/mitmproxy/addons/test_blocklist.py @@ -22,20 +22,21 @@ def test_parse_spec_err(filter, err): class TestBlockList: @pytest.mark.parametrize( - "filter,status_code", + "filter,request_url,status_code", [ - (":~u example.org:404", 404), - (":~u example.com:404", None), - ("/!jpg/418", None), - ("/!png/418", 418), + (":~u example.org:404", b"https://example.org/images/test.jpg", 404), + (":~u example.com:404", b"https://example.org/images/test.jpg", None), + (":~u test:404", b"https://example.org/images/TEST.jpg", 404), + ("/!jpg/418", b"https://example.org/images/test.jpg", None), + ("/!png/418", b"https://example.org/images/test.jpg", 418), ], ) - def test_block(self, filter, status_code): + def test_block(self, filter, request_url, status_code): bl = blocklist.BlockList() with taddons.context(bl) as tctx: tctx.configure(bl, block_list=[filter]) f = tflow.tflow() - f.request.url = b"https://example.org/images/test.jpg" + f.request.url = request_url bl.request(f) if status_code is not None: assert f.response.status_code == status_code