make url filters case-insensitive (#6493)

fix #6329
This commit is contained in:
Emanuele Micheletti 2023-12-12 19:33:19 +01:00 committed by GitHub
parent 13c976de0d
commit b84a821fd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 7 deletions

View File

@ -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.

View File

@ -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".

View File

@ -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