Skip to content

Guard app reads against malformed payloads and invalid dates - #549

Closed
Ayush7614 wants to merge 2 commits into
CopilotKit:mainfrom
Ayush7614:feat/app-resilience-guards
Closed

Ayush7614 wants to merge 2 commits into
CopilotKit:mainfrom
Ayush7614:feat/app-resilience-guards

Conversation

@Ayush7614

Copy link
Copy Markdown
Contributor

Control reads threw out of response.json on non-JSON bodies and rejected the panel poll; they now answer null on malformed shapes. client envelope unwrap threw TypeError on null/array bodies; it now throws the caller fallback. socketUrl interpolated unchecked WS ports so bad values threw in WebSocket constructors; only 1-65535 digits override same-origin. Screenshot and page-frame readers shape-check before atob; live-screen drops non-finite dimensions and oversized payloads; relativeTime returns the input on invalid dates.

Verified: bun test app/tests/app-resilience-guards.test.ts app/tests/socket-url.test.ts — 16 pass, 0 fail. Biome lint and format clean.

Control reads threw out of response.json on non-JSON bodies and
rejected the panel poll; they now answer null on malformed shapes.
client envelope unwrap threw TypeError on null/array bodies; it now
throws the caller fallback. socketUrl interpolated unchecked WS ports
so bad values threw in WebSocket constructors; only 1-65535 digits
override same-origin. Screenshot and page-frame readers shape-check
before atob; live-screen drops non-finite dimensions and oversized
payloads; relativeTime returns the input on invalid dates.
@davidmckayv

Copy link
Copy Markdown
Contributor

Thanks — the guards themselves are right and the tests cover the cases well. One blocker: bun run typecheck fails on the app workspace because the fetch mocks are cast straight to typeof fetch:

tests/app-resilience-guards.test.ts(58,24): error TS2352: Conversion of type '() => Promise<Response>' to type 'typeof fetch' may be a mistake because neither type sufficiently overlaps with the other.

Four spots (lines ~62, 72, 84, 96). Cast through unknown:

})) as unknown as typeof fetch;

Push that and CI goes green — happy to merge it straight after.

davidmckayv added a commit that referenced this pull request Sep 15, 2026
The app read several server responses without checking their shape: the shared client
did `(await response.json())[key]` and threw on a 204 or a non-JSON body; the computer
control and screen readers cast unchecked payloads and threw in the viewer; relative-time
fed NaN into the formatter; and the socket URL interpolated an unvalidated port, throwing
synchronously in `new WebSocket()`. Each now degrades gracefully — a real HTTP error still
surfaces the server's message, only a malformed 2xx body falls back — without hiding a
genuine failure.

Originally #549 by Ayush7614, folded in here with the fetch mocks in the test cast through
`unknown` so the app typechecks; the fork branch could not take that one-line fix directly.
@davidmckayv

Copy link
Copy Markdown
Contributor

Landed in #561 (your change + a one-line test-cast fix so the app typechecks). GitHub wouldn't let me push the fix to this branch directly, so I folded it in there, credited to you. Thanks!

@davidmckayv

Copy link
Copy Markdown
Contributor

Superseded by #561 — merged. Thanks @Ayush7614.

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