# aMQTT: Inefficient Regular Expression Complexity and Uncontrolled Resource Consumption and Improper Input Validation

aMQTT broker accepts malformed topic filters with many '+' wildcards, causing catastrophic regex backtracking that blocks the event loop and freezes the broker.

- Payout: Research
- Severity: high
- Program: aMQTT
- Found by: zljfx
- Disclosed: 2026-11-20
- CVE: CVE-2026-104199
- Write-up quality: 7/10
- Original: https://github.com/advisories/GHSA-2hjf-7455-w946
- Library page: https://bugbountylibrary.com/r/ghsa%3AGHSA-2hjf-7455-w946
- Tags: area:devices domain:network impact:dos kind:research platform:ghsa sev:high tech:python technique:source-review vuln:dos

**Target:** MQTT broker topic-filter validation and matching
**Root cause:** add_subscription() validates '+' placement with substring checks for '/+' and '+/' instead of requiring each level containing '+' to be exactly '+', and _matches() expands each '+' into greedy `[^/]*` evaluated with re.fullmatch(), enabling catastrophic backtracking.
**Steps:**
1. Open a raw MQTT 3.1.1 TCP connection to the broker (anonymous by default).
2. Send a SUBSCRIBE packet with a malformed filter such as `"+/" + "+" * 60`, which passes validation instead of being rejected with 0x80.
3. Send a PUBLISH packet whose topic partially matches but ultimately fails against the filter.
4. The synchronous re.fullmatch() in the global broadcast loop backtracks catastrophically, blocking the asyncio event loop.
5. Observe broker freeze: no message delivery, no CONNACK for new connections, keepalive and broadcast stop until restart.
**How found:** Reporter noticed add_subscription() used substring checks for '/+' and '+/' rather than per-level validation, allowing filters like `"+/" + "+" * 60`, then traced how _matches() converts each '+' to greedy `[^/]*` and runs re.fullmatch() synchronously in the broadcast loop, hypothesizing catastrophic backtracking.
**Exploitation:** A single unauthenticated client sends one crafted SUBSCRIBE with many adjacent '+' wildcards followed by one PUBLISH to a partially-matching topic; the regex match runs synchronously in the broker's broadcast loop and blocks all broker processing until the process is restarted.
**Insight:** When a wildcard matcher translates user input into regex fragments, count how many greedy quantifiers can be adjacent in one expression and whether matching runs on a shared synchronous loop; substring-based wildcard placement checks miss stacked wildcards within a single level.

