fix(identity): allow_from fallthrough for Matrix user IDs with colon#3045
fix(identity): allow_from fallthrough for Matrix user IDs with colon#3045chengzhichao-xydt wants to merge 2 commits into
Conversation
|
Hi @chengzhichao-xydt, thanks for digging into this, I think the underlying bug is real, but I don't think this patch fully fixes it yet. For Matrix, So unless I'm missing something, I think we need one of these instead:
Could you also add a regression test for the Matrix case in |
d04e4fc to
e932e81
Compare
ParseCanonicalID splits on first colon, misinterpreting @alice:example.com as platform:id. Two fixes: 1. When canonical match fails, fall through to legacy match strategies instead of returning false. 2. In the legacy path, preserve the leading @ for entries containing a colon, since the @ is part of a Matrix-style user ID, not a username prefix. Add regression tests for Matrix ID matching via both PlatformID and canonical format. Fixes sipeed#3044.
e932e81 to
1ab06b5
Compare
|
pkg/identity/identity.go The new fallthrough overly broadens the match for canonical pkg/identity/identity_test.go One of the new tests does not exercise the bug fixed by the PR. The case |
…tching
When a canonical "platform:id" entry fails to match, return false
immediately instead of falling through to legacy PlatformID matching.
Previously, an allow-list entry like "discord:98765432" that didn't
match the canonical path could be satisfied by a sender with
Platform=matrix and PlatformID=discord:98765432 — an unintended
authorization widening.
Only Matrix-style IDs ("@user:domain") and numeric compound IDs now
fall through to legacy matching, since their colon is part of the ID,
not a canonical separator.
Adds regression test verifying the security boundary.
|
Thanks for the detailed review. Addressed in dfc66d0:
|
|
This PR has had no activity for 7 days and has been marked as stale. If you are still working on it, please push an update or leave a comment; otherwise it will be closed automatically in 7 days. |
Problem
allow_fromsilently rejects messages from Matrix users when using the standard Matrix user ID format (@alice:example.com). Fixes #3044.Root cause:
ParseCanonicalIDsplits on the first colon, so@alice:example.comis parsed asplatform="@alice",id="example.com". Since@aliceis not numeric, the code enters the canonical-match branch and builds"@alice:example.com"as the candidate — which doesn't matchsender.CanonicalID("matrix:@alice:example.com"). The function then returnedfalseimmediately, never trying the remaining PlatformID or Username match strategies.Fix
When the canonical match fails but a colon was present, fall through to the remaining match strategies (PlatformID, Username) instead of returning early. This allows Matrix-style IDs to still match via the legacy paths.
Changes
pkg/identity/identity.go: refactor early returns into fallthroughVerification
go build ./pkg/identity/...passesgo test ./pkg/identity/...passes (all existing tests green)