Skip to content

fix(app): guard channel socket against malformed payloads - #381

Merged
davidmckayv merged 2 commits into
CopilotKit:mainfrom
Ayush7614:fix/channel-socket-payload-guard
Sep 5, 2026
Merged

fix(app): guard channel socket against malformed payloads#381
davidmckayv merged 2 commits into
CopilotKit:mainfrom
Ayush7614:fix/channel-socket-payload-guard

Conversation

@Ayush7614

Copy link
Copy Markdown
Contributor

The socket try/catch only covered JSON.parse, but JSON.parse('null') succeeds with null and JSON.parse('5') with 5. null reached isResync and threw TypeError on null.resync inside onmessage; numbers/strings/arrays passed through with channelId undefined, causing applyChannelEvent to return 'unknown' and a spurious roster-wide refetch. Binary frames (Blob) also relied on a cast.

Change: null-safe isResync(unknown), isChannelSocketMessage guard, and parseChannelSocketMessage() used by onmessage so unusable frames are dropped (no crash, no refetch). New app/tests/channel-socket-message.test.ts (32 tests).

Verified: new file 32 pass; existing channel-event-patch 14 pass; app tsc clean.

@davidmckayv davidmckayv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed diff against current main; resolved CHANGELOG keep-both; validated locally (format + composed test run). CI green.

@davidmckayv
davidmckayv merged commit e602259 into CopilotKit:main Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants