From c7186dfe506e38ad19994a270fd394fa94d07570 Mon Sep 17 00:00:00 2001 From: Laurens <43173895+GreenGrassBlueOcean@users.noreply.github.com> Date: Tue, 10 Nov 2026 20:58:57 +0100 Subject: [PATCH] fix(gateway): eliminate ReDoS ambiguity in _WHO4_QUERY_RE (CodeQL #8) --- custom_components/myhome/gateway_sessions.py | 2 +- tests/test_issue_886_myhomeserver1_41_zones.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/custom_components/myhome/gateway_sessions.py b/custom_components/myhome/gateway_sessions.py index 5df70c70..8faef4e8 100644 --- a/custom_components/myhome/gateway_sessions.py +++ b/custom_components/myhome/gateway_sessions.py @@ -526,7 +526,7 @@ def _is_status_report_item(item: Any) -> bool: ) -_WHO4_QUERY_RE = re.compile(r"^\*#4\*(?P[^#*]+(?:#[^*]+)*)(?:\*(?P\d+))?##$") +_WHO4_QUERY_RE = re.compile(r"^\*#4\*(?P[^#*]+(?:#[^#*]+)*)(?:\*(?P\d+))?##$") _WHO4_REPLY_RE = re.compile( r"^\*(?:#4\*(?P[^*]+)\*.*|4\*[^*]+\*(?P[^*]+))##$" ) diff --git a/tests/test_issue_886_myhomeserver1_41_zones.py b/tests/test_issue_886_myhomeserver1_41_zones.py index 6b6a59eb..0c491928 100644 --- a/tests/test_issue_886_myhomeserver1_41_zones.py +++ b/tests/test_issue_886_myhomeserver1_41_zones.py @@ -588,6 +588,15 @@ async def test_pause_status_edge_cases_and_mixed_non_who4_collected_frames( _mismatched_who4_reply_zones("*#4*60##", ["*1*1*11##", "*#4*34*0*0146##"]) == {"34"} ) + # Multi-segment WHERE (`#4#01`) and linear-time rejection of malformed `#`-repeated input (CodeQL py/redos) + assert ( + _mismatched_who4_reply_zones("*#4*60#4#01*60##", ["*#4*34#4#01*60*55##"]) + == {"34"} + ) + assert ( + _mismatched_who4_reply_zones("*#4*1" + "#a" * 40 + "!", ["*#4*34*0*0146##"]) + is None + ) scheduler = FrameScheduler() try: