Skip to content

fix: ACL bypass and # wildcard zero-children in MatchTopic - #170

Merged
wind-c merged 3 commits into
mainfrom
fix/acl-prefix-topic-bypass
Jul 12, 2026
Merged

wind-c merged 3 commits into
mainfrom
fix/acl-prefix-topic-bypass

Conversation

@wind-c

@wind-c wind-c commented Jul 12, 2026 •

Copy link
Copy Markdown
Owner

#170 - MatchTopic fixes

Fix 1: ACL bypass via prefix topic matching (CVSS 4.3)

Reported by Team Atlanta. MatchTopic returned true unconditionally after exhausting filter parts, without checking whether topic parts remain. A literal filter "allowed" matched publish to "allowed/secret".
Fix: return len(topicParts) == len(filterParts)

Fix 2: # wildcard zero-children matching

Per MQTT 4.7 spec, # must match zero or more child levels. The bounds check returned false before checking if filter part was #, so a/# failed to match a.
Fix: matched = filterParts[i] == "#"

Changes

mqtt/hooks/auth/ledger.go 2+
mqtt/hooks/auth/ledger_test.go 16+

Reported by Team Atlanta.

MatchTopic returned true unconditionally after exhausting filter parts,
without checking whether topic parts remained. A literal filter 'allowed'
matched publish to 'allowed/secret'.

Fix: return elements, len(topicParts) == len(filterParts).
The '#' multi-level wildcard path returns early, unaffected.

Reported by Team Atlanta.
@wind-c wind-c changed the title Fix/acl prefix topic bypass fix: ACL bypass and # wildcard zero-children in MatchTopic Jul 12, 2026
Per MQTT 4.7 spec, the '#' multi-level wildcard must match zero or more sublevels.
The bounds check returned false before checking if the filter part was '#'.

Fix: matched = filterParts[i] == '#', only allow zero-children on '#'.
Regular filters and '+' wildcard still require exact level count.

Test: MatchTopic('a/#', 'a') -> true, MatchTopic('a/+', 'a') -> false.
Updated TestCanACL expectation: topic 'updates' is now correctly denied
for read because global rule 'updates/#' (WriteOnly) matches 'updates'
with the zero-children fix.
@wind-c
wind-c force-pushed the fix/acl-prefix-topic-bypass branch from 3744ca3 to 58e7e95 Compare July 12, 2026 07:12
@wind-c
wind-c merged commit aff5731 into main Jul 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant