Comfy-Org / Comfy-Org/ComfyUI_frontend
feat: add Zod schema validation for server capabilities JSON response
- Dominant language
- TypeScript
- Stars
- 2k
- Forks
- 699
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 490
Description
## Summary
Add Zod schema validation to the `initServerCapabilities()` function in `src/services/serverCapabilities.ts` to guard against malformed server responses affecting security-sensitive flags (e.g., `teamWorkspacesEnabled`).
## Background
In PR #9094, the `/api/features` JSON response is stored directly without schema validation. Currently, consumers provide defaults via `getServerCapability(key, defaultValue)`, so malformed data degrades gracefully — but explicit validation would provide an additional safety layer for security-sensitive capability flags.
## Proposed Work
- Define a Zod schema (following the existing pattern in `src/platform/assets/schemas/assetSchema.ts`) for the server capabilities object returned by `GET /api/features`.
- In `initServerCapabilities()`, call `schema.safeParse()` on the parsed JSON result (per the established pattern of using `safeParse()` over `parse()` to avoid leaking internal schema details).
- On parse failure, log a user-friendly warning via `fromZodError(result.error)` and fall back to `EMPTY`.
- Add/update unit tests in `src/services/serverCapabilities.test.ts` to cover schema validation success and failure paths.
## References
- PR: https://github.com/Comfy-Org/ComfyUI_frontend/pull/9094
- Comment: https://github.com/Comfy-Org/ComfyUI_frontend/pull/9094#discussion_r2867431083
- Requested by: @christian-byrne
┆Issue is synchronized with this [Notion page](https://www.notion.so/Issue-9826-feat-add-Zod-schema-validation-for-server-capabilities-JSON-response-3216d73d3650810e9f0ed310a28b42d0) by [Unito](https://www.unito.io)
Contributor guide
Assessment
This issue has not been assessed yet.