Repository navigation
fix(harness): make the gateway session key injective - #3592
Closed
King52HerTz wants to merge 1 commit into
Closed
King52HerTz wants to merge 1 commit into
King52HerTz wants to merge 1 commit into
Conversation
MsgContext.canonicalKey() joined its routing components with a bare '|' and
never escaped that separator inside a value, so a single component could
imitate another label: group "team|r:room-1" produced exactly the key of group
"team" plus room "room-1". The key is what the gateway derives the session id,
the per-key turn gate and the session-to-key wake-up map from, so a collision
routes two distinct conversations onto one gateway session.
The same hole exists on the extra map, where one entry's value can spell out a
whole second "|x:" entry, and on the channel component.
Escape '%' before '|' inside every component ('%' first, so the escape itself
stays unambiguous). Components containing neither character - the common case -
are returned unchanged, so existing session keys and their derived ids do not
move.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
Author
|
Closing this PR to avoid maintaining overlapping fixes for the same routing-key collision issue. The earlier PR #3535 addresses this problem; please continue the discussion there. Thanks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Closes #3534.
MsgContext.canonicalKey()joins the routing components with a bare|and does not escape that separator inside a value, so the key is not injective: one component can imitate another label.The key is load-bearing, not a display string:
HarnessGatewayderives the session id from it (SessionIdUtils.deterministicHash, a 12-char hex), keys the per-session turn gate with it, and keeps a session-id -> key reverse map for wake-up driven runs. A collision therefore routes two genuinely different conversations onto one gateway session - one group/room's participants end up in the other's conversation state and turn serialisation.Two more cases in the same family that the report doesn't mention:
extramap is joined the same way, so one entry's value can spell out a whole second entry:Map.of("a", "b|x:c=d")andMap.of("a", "b", "c", "d")produce the identical key.channelcomponent is concatenated raw too, so a channel namedchatui|g:teamcollides with channelchatuiplus groupteam.Change
Escape
%and|inside every component - channel, group, room, threadId, threadTs, and both halves of eachextraentry - so|occurs in the key only as a separator and%only as an escape introducer.%is escaped before|; the opposite order would re-escape the%it just wrote and make a literal%7Cvalue collide with a literal|one.Compatibility - the one thing to review
The escape is conditional: a component containing neither character is returned unchanged. Ordinary channel/group/room/thread ids contain neither, so existing keys, and therefore the session ids hashed from them, stay byte-identical and nothing needs migrating. The only conversations whose key changes are those whose ids literally contain
%or|- exactly the ones that could previously be collided with another conversation, and they will start a fresh session rather than continuing in a shared one. There is a test pinning the unchanged shape of an ordinary key.Deliberately not included
trim()ed, sogroup = " "is still equivalent to no group. That collapses to the same conversation by design; it is not a way to imitate a second component, so I left it alone rather than widening the change.userIdstill does not participate in the key, as the class documents.Testing
6 new tests in
MsgContextCanonicalKeyTest: the reported collision, the channel variant, the extra-value-forges-an-entry variant, the%7Cvs|ordering case, an exact-key regression guard for ordinary ids, and stability of the derived session id.Mutation matrix - each breaks the product code only:
before%`)extrakeys/values only