-
Notifications
You must be signed in to change notification settings - Fork 107
Description
Problem
Currently, Cap'n Web allows using TypeScript for compile-time type checking, a common use case would be importing the server types wither directly in a mono-repo or using a generated.d.ts file. But it lacks runtime validation for method arguments. This creates potential security vulnerabilities as input from network boundaries should never be trusted implicitly. In production TypeScript applications, type mismatches can occur due to:
- External API responses that don't match expected schemas
- Client-side tampering with RPC payloads
- Version mismatches between client and server code
- JavaScript clients calling TypeScript servers
Proposed Solution
Add optional runtime type validation for RPC method arguments, similar to how tRPC handles it - where you can define validators that run on both input and output to ensure type safety across network boundaries.
Implementation Suggestion
Support https://github.com/standard-schema/standard-schema as the validation interface. This would allow users to choose from any compatible validation library (Zod, Valibot, Arktype, etc.) without locking them into a specific ecosystem. Since Standard Schema is just a specification, it wouldn't add runtime dependencies to Cap'n Web itself.
I'm not sure about the actual API DX.