fix(webchat): scope conversationId by channel id (#558)#562
Open
ncw1992120 wants to merge 1 commit into
Open
Conversation
deriveConversationId identified a channel by the first 8 chars of its apiKey, but all generated keys share the 11-char prefix "mc_webchat_", so the slice was the constant "mc_webch" for every channel. Two channels with the same visitorId derived the SAME conversationId, collapsing their sessions β channel isolation was lost. Scope the conversationId by channel.getId() (the stable DB primary key), mirroring the IM-channel fix in e294b32: - deriveConversationId now takes Long channelId; format webchat:<channelId>:<visitor>[:<session>] - the VARCHAR(128) widening (V171, e294b32) means the hash-folding branch is no longer needed β removed - loadVisitorSessions filters by the channel-scoped prefix exactly No channel_id column, no read-time legacy fallback, no new migration β consistent with e294b32's approach. Pre-fix sessions keyed by the old mc_webch prefix are not migrated (same posture as the IM fix). Tests: WebChatChannelIsolationTest seeds two channels sharing an apiKey prefix + same visitor, asserts each channel lists only its own sessions (the regression). Full WebChat* suite green (106 tests).
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.
What
Fixes the WebChat side of #558 β channel session isolation. Companion to the IM-channel fix in
e294b325(already ondev), using the same approach.The bug:
deriveConversationIdidentified a channel by the first 8 chars of its apiKey. All generated keys share the 11-char prefixmc_webchat_, so that slice was the constantmc_webchfor every channel. Two channels with the samevisitorIdderived the sameconversationId, collapsing their sessions together (cross-leak inlistSessions,UNIQUEcollisions).Fix
Scope the conversationId by
channel.getId()(the stable DB primary key), mirroringe294b325:deriveConversationId(Long channelId, ...)β formatwebchat:<channelId>:<visitor>[:<session>]VARCHAR(128)widening from V171 (e294b325) means the hash-folding branch is no longer needed β removed, simplifying the derivationloadVisitorSessionsfilters by the channel-scoped prefixwebchat:<channelId>:exactlyNo
channel_idcolumn, no read-time legacy fallback, no new migration β consistent withe294b325's posture. Pre-fix sessions keyed by the oldmc_webchprefix are not migrated (same as the IM fix: old sessions are not carried forward).Tests
WebChatChannelIsolationTestβ the core regression: two channels sharing an apiKey prefix + same visitorId β each channel'slistSessionsreturns only its own sessions (channel B's session does NOT appear in channel A).deriveConversationIdcall sites tochannelId.WebChat*suite green (106 tests, 0 failures).Relationship to PR #561
This supersedes #561, which used a
channel_idcolumn + read-time fallback. That approach introduced a cross-channel leak in the legacy-prefix fallback. This PR adoptse294b325's simpler, proven approach instead. #561 should be closed.