Repository navigation
4.21.0
Security
Logging out, or another user signing in on the same page, no longer has to carry the previous user's data or queued
messages into the next user's session. Before, the documented steps (close() on logout, reconnect() on an account
switch) reset only the socket: the next user could see the previous user's last message, feed positions, runs and
agent thread, and could send their queued outbox entries. See
Logging out and switching accounts.
Added
feeds.reset(topic?)forgets the position of a topic, or of every topic, so the next subscription starts from the
beginning instead of from the previous user's last message.runs.clear()forgets every run, in memory and in storage, including unsent starts and pending cancels. It sends
nothing.agent.reset()(AG-UI) forgets the thread, starts the next run fromstate, and picks a new thread id unless one
was given.createTabsWebSocket({ session }): tabs share a connection only with tabs that return the same session, such as
the user's id, so the next user gets a connection of their own.
Changed
close()also clearslastMessage, as it already cleared the send queue and amigrate()target. Components
that renderlastMessageshowundefinedafterclose()until a message arrives.
Fixed
outbox.clear()removes every entry that exists when it's called. It used to keep entries whose timestamps were
ahead of the clearing tab's clock, as after the clock is set back or after another tab added many entries at once,
and they were then sent on the next connection.
Documentation
- The authentication guide covers logging out and switching accounts: call
close()and reset what the managers
keep, thenconnect(), rather thanreconnect(), which keeps the send queue. Servers should close a user's open
sockets when their session ends.SECURITY.mdsays the same. - The recipes' servers check every message before using it: JSON, a known
type, and the fields that type needs.
Anything else closes only that client's socket with1003, which the client doesn't retry, where a malformed
message used to throw and stop the whole server. Every server socket gets anerrorlistener, and the voice
assistant's connection to the provider does too. - The live notifications recipe refuses to start without a
SOCKET_SECRETof at least 32 characters, where it used
to sign tokens with an empty key that anyone could reproduce.verifyTokenrejects tokens that aren't strings or
don't have three parts, and compares the signatures' bytes, not their characters. - The team chat, collaborative whiteboard and delivery tracking recipes clear their outbox on sign-out, and the live
notifications recipe also forgets its feed position. - The Next.js, Astro and Remix examples' demo servers survive malformed messages, limit messages to 64 KiB, accept
only palette colors and on-pad cursor positions, and their cursors paint the color withbackgroundColor, so a
peer can't make other viewers' browsers load a URL.