Summary
RabbitMQ's MQTT plugin supports topic-level authorization using regular expressions that interpolate user-controlled values such as client_id.
Because these values are inserted into regex patterns without escaping special characters, an authenticated MQTT client can inject regex operators to bypass topic access restrictions.
Affected context
This vulnerability affects RabbitMQ deployments that:
- Enable and rely on the MQTT plugin for client communication
- Use topic-level authorization rules expressed as regular expressions
- Include user-controlled variables like
{client_id}in regex patterns
The risk is present when access control policies assume that interpolated values are literal strings, but the underlying implementation treats them as part of a regex, allowing special characters to alter the pattern.
Exploit preconditions
- Attack surface: MQTT interface exposed by RabbitMQ (network-accessible MQTT port).
- Required access: Valid MQTT credentials (authenticated user) and the ability to choose or influence the
client_idin the CONNECT packet. - Trigger point: Authorization checks that construct regex patterns using unescaped
{client_id}(or similar variables) when matching publish/subscribe topics. - Why exploitation is possible: The implementation interpolates the raw
client_iddirectly into the regex pattern without escaping regex metacharacters. An attacker can embed regex operators in theclient_id, causing the resulting pattern to match topics beyond the intended scope and bypass policy constraints.
Why this happens
The core issue is improper authorization logic stemming from unsafe use of regular expressions in access control rules.
Instead of treating user-controlled values (e.g., client_id) as literal strings, the system interpolates them directly into regex patterns. Regex engines interpret characters like . * ? + | and grouping constructs as operators, so a crafted client_id can expand or alter the match space significantly.
This maps to CWE-863: Incorrect Authorization because the authorization mechanism is logically flawed: it assumes that the pattern constraints accurately represent the intended permissions, but the unescaped interpolation allows a malicious client to redefine the effective rules at runtime.
Abstractly, this is an insecure pattern where policy logic is coupled to a powerful pattern-matching language without robust escaping or canonicalization of untrusted inputs used inside those patterns.
Potential impact
- MQTT clients may access topics they are not intended to publish to or subscribe from.
- Unauthorized reading of sensitive telemetry, event streams, or inter-service messages.
- Injection of forged messages into protected topics, potentially leading to data tampering or business logic abuse in downstream consumers.
- Lateral movement between logical tenants or customers within a multi-tenant RabbitMQ deployment.
- Violation of segregation-of-duties or per-device isolation guarantees, impacting compliance and auditability.
General mitigation guidance
Effective mitigation focuses on hardening authorization expressions and decoupling them from untrusted regex input:
- Treat user-controlled identifiers (such as
client_id) as literal values when used in access control patterns by applying strict escaping before interpolation into any regular expression. - Prefer exact string comparisons or prefix checks for topic authorization where possible instead of full regexes, reducing the complexity and attack surface of policy evaluation.
- Introduce a layer that normalizes and validates identifiers (length limits, allowed character sets) before they are used in authorization rules; restricting
client_idto a safe character set can greatly reduce misuse. - Design authorization policies to be deny-by-default, granting only the minimum set of topics needed, so that any pattern expansion has limited blast radius.
- Consider separating policy configuration from user-controlled naming schemes, e.g., mapping client IDs to internal identifiers that are used in access control rules.
How teams detect issues like this
Organizations can detect and monitor for this class of issue via:
- Configuration review: Examine MQTT authorization rules for regex-based policies that interpolate variables like
{client_id},{username}, or other untrusted values without explicit escaping or normalization. - Code analysis: Use static analysis or manual review to find authorization paths where regex construction includes user input, especially where pattern strings are built via concatenation or templating.
- Security testing: Perform targeted tests with
client_idvalues containing regex metacharacters to confirm whether topic access expands unexpectedly compared to the policy intent. - Logging and monitoring: Enable detailed authorization logs for MQTT operations; alert on anomalous topic access patterns (e.g., a single client accessing many tenants' topics or unexpected topic namespaces).
- Policy enforcement in CI/CD: Integrate linters or custom policy checks into deployment pipelines to flag new or modified regex-based access-control rules that embed user-controlled variables.

