Skip to content

Commit

Permalink
make url filters case-insensitive (mitmproxy#6493)
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuele-em committed Dec 12, 2023
1 parent 13c976d commit b84a821
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions mitmproxy/flowfilter.py
Expand Up @@ -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".

Expand Down
15 changes: 8 additions & 7 deletions test/mitmproxy/addons/test_blocklist.py
Expand Up @@ -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
Expand Down

0 comments on commit b84a821

Please sign in to comment.