From c5402a490a20cc014e350f2b353dca6eec4bf29b Mon Sep 17 00:00:00 2001 From: Sujal Singh Date: Mon, 27 Jan 2025 19:29:27 +0530 Subject: [PATCH] Check `flow.killable` before killing prior knowledge h2 connections. (#7514) * check for killable flow * [autofix.ci] apply automated fixes * add test * changelog * restructure test * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- CHANGELOG.md | 2 ++ mitmproxy/addons/disable_h2c.py | 3 ++- test/mitmproxy/addons/test_disable_h2c.py | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1198bb458..84e4d8cea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ ([#7497](https://github.com/mitmproxy/mitmproxy/pull/7497), @sujaldev) - Add mitmweb tutorial to docs. ([#7509](https://github.com/mitmproxy/mitmproxy/pull/7509), @EstherRoeth) +- Fixed a bug that caused mitmproxy to crash when loading prior knowledge h2 flows. + ([#7514](https://github.com/mitmproxy/mitmproxy/pull/7514), @sujaldev) ## 12 January 2025: mitmproxy 11.1.0 diff --git a/mitmproxy/addons/disable_h2c.py b/mitmproxy/addons/disable_h2c.py index ae9e3f94e..432dc5424 100644 --- a/mitmproxy/addons/disable_h2c.py +++ b/mitmproxy/addons/disable_h2c.py @@ -30,7 +30,8 @@ class DisableH2C: and f.request.http_version == "HTTP/2.0" ) if is_connection_preface: - f.kill() + if f.killable: + f.kill() logging.warning( "Initiating HTTP/2 connections with prior knowledge are currently not supported." ) diff --git a/test/mitmproxy/addons/test_disable_h2c.py b/test/mitmproxy/addons/test_disable_h2c.py index 4d55ecfe4..1e6267167 100644 --- a/test/mitmproxy/addons/test_disable_h2c.py +++ b/test/mitmproxy/addons/test_disable_h2c.py @@ -37,3 +37,18 @@ class TestDisableH2CleartextUpgrade: a.request(f) assert not f.killable assert f.error.msg == flow.Error.KILLED_MESSAGE + + def test_non_killable_flows(self): + with taddons.context() as tctx: + a = disable_h2c.DisableH2C() + tctx.configure(a) + + f = tflow.tflow() + f.request = tutils.treq( + method=b"PRI", + path=b"*", + http_version=b"HTTP/2.0", + ) + f.kill() + + a.request(f)