Skip to content

fix(webchat): discard corrupted guest conversation ids and surface load failures - #1609

Merged
realcodesiman merged 1 commit into
mainfrom
fix/webchat-guest-session-corrupted-id
Nov 2, 2026
Merged

realcodesiman merged 1 commit into
mainfrom
fix/webchat-guest-session-corrupted-id

Conversation

@realcodesiman

Copy link
Copy Markdown
Contributor

Problem

createGuestSessionStore#initGuestSession trusted any guest conversation id found in localStorage (scoped or legacy) without validating its shape. A corrupted/stale value (e.g. leftover from an older widget version) was forwarded as-is to the guest message API, which always 400s on it — permanently stranding that visitor's session until they manually clear storage.

Separately, WebchatMessageList called loadMoreMessages without a .catch. That function only console.errors + rethrows on failure (network error, rate limit, invalid guest id), so the rejection was silently swallowed and the visitor saw an empty chat with no indication anything went wrong.

Fix

  • isValidGuestConversationId (new, in guest-conversation-id.ts) validates a stored id against the existing GUEST_CONVERSATION_ID_REGEX.
  • initGuestSession now discards a scoped or legacy stored id that fails validation (with a console.warn), falls back to the server-minted id for this page load, and overwrites storage so the corrupted value doesn't persist.
  • WebchatMessageList now catches a failed initial loadMoreMessages and surfaces a toast.error via a new webchat.loadMessagesError translation key (added to all locales).

Testing

  • Added two regression tests: a corrupted scoped id and a corrupted legacy id both fall back to the server-minted id and overwrite storage.
  • pnpm --filter builder check-types — pass.
  • pnpm lint (includes i18n:check and ultracite check) — pass, no missing/invalid translation keys.

@github-actions github-actions Bot added the bug Something isn't working as expected label Oct 31, 2026
@realcodesiman
realcodesiman merged commit 1d4c421 into main Nov 2, 2026
15 checks passed
@realcodesiman
realcodesiman deleted the fix/webchat-guest-session-corrupted-id branch November 2, 2026 03:21
hello-jackytruong referenced this pull request in hello-jackytruong/ChatWorkAI Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant