Improve HTTP detection heuristic (#7228)
Some checks failed
autofix.ci / autofix (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / filename-matching (push) Has been cancelled
CI / mypy (push) Has been cancelled
CI / individual-coverage (push) Has been cancelled
CI / test (macos-latest, 3.13-dev) (push) Has been cancelled
CI / test (ubuntu-latest, 3.10) (push) Has been cancelled
CI / test (ubuntu-latest, 3.11) (push) Has been cancelled
CI / test (ubuntu-latest, 3.12) (push) Has been cancelled
CI / test (ubuntu-latest, 3.13-dev) (push) Has been cancelled
CI / test (windows-latest, 3.13-dev) (push) Has been cancelled
CI / test-old-dependencies (push) Has been cancelled
CI / build (macos-12, macos-x86_64) (push) Has been cancelled
CI / build (macos-14, macos-arm64) (push) Has been cancelled
CI / build (ubuntu-20.04, linux) (push) Has been cancelled
CI / build (windows-2019, windows) (push) Has been cancelled
CI / build-wheel (push) Has been cancelled
CI / build-windows-installer (push) Has been cancelled
CI / test-web-ui (push) Has been cancelled
CI / docs (push) Has been cancelled
CI / test-docker (push) Has been cancelled
CI / check (push) Has been cancelled
CI / deploy-docker (push) Has been cancelled
CI / deploy (push) Has been cancelled

* Improve HTTP checking heuristic

* fix changelog

* Fix checking

* [autofix.ci] apply automated fixes

* simplify condition

---------

Co-authored-by: Fata Nugraha <fata.nugraha@grabtaxi.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Maximilian Hils <github@maximilianhils.com>
This commit is contained in:
Fata Nugraha 2024-10-04 23:22:26 +08:00 committed by GitHub
parent 870dd03b17
commit af88265f5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 4 deletions

View File

@ -7,6 +7,8 @@
## Unreleased: mitmproxy next
- Tighten HTTP detection heuristic to better support custom TCP-based protocols.
([#7228](https://github.com/mitmproxy/mitmproxy/pull/7228), @fatanugraha)
## 02 October 2024: mitmproxy 11.0.0

View File

@ -182,9 +182,10 @@ class NextLayer:
probably_no_http = (
# the first three bytes should be the HTTP verb, so A-Za-z is expected.
len(data_client) < 3
# HTTP would require whitespace before the first newline
# if we have neither whitespace nor a newline, it's also unlikely to be HTTP.
or (data_client.find(b" ") >= data_client.find(b"\n"))
# HTTP would require whitespace...
or b" " not in data_client
# ...and that whitespace needs to be in the first line.
or (data_client.find(b" ") > data_client.find(b"\n"))
or not data_client[:3].isalpha()
# a server greeting would be uncharacteristic.
or data_server

View File

@ -103,7 +103,7 @@ dns_query = bytes.fromhex("002a01000001000000000000076578616d706c6503636f6d00000
# Custom protocol with just base64-encoded messages
# https://github.com/mitmproxy/mitmproxy/pull/7087
custom_base64_proto = b"AAAAAAAAAAAAAAAAAAAAAA=="
custom_base64_proto = b"AAAAAAAAAAAAAAAAAAAAAA==\n"
http_get = b"GET / HTTP/1.1\r\nHost: example.com\r\n\r\n"
http_get_absolute = b"GET http://example.com/ HTTP/1.1\r\n\r\n"