feat(server)!: default CORS origin to "*" and support async origin options - #1914
Conversation
…tions CORSHandlerPlugin now defaults origin to "*" instead of reflecting the request origin, and the origin/timingOrigin options accept async functions so the allowed origin can be resolved per request from the handler context.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
More templates
@orpc/ai-sdk
@orpc/arktype
@orpc/bun
@orpc/client
@orpc/cloudflare
@orpc/contract
@orpc/experimental-effect
@orpc/evlog
@orpc/hibernation
@orpc/json-schema
@orpc/experimental-msw
@orpc/nest
@orpc/next
@orpc/node
@orpc/openapi
@orpc/opentelemetry
@orpc/pinia-colada
@orpc/pino
@orpc/publisher
@orpc/ratelimit
@orpc/server
@orpc/shared
@orpc/swr
@orpc/tanstack-query
@orpc/trpc
@orpc/valibot
@orpc/zod
commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
ℹ️ Minor suggestion — the change is well-scoped, documented, and tested. One footgun worth a thought before merge.
Reviewed changes
- Defaulted
originto'*'in the CORS handler plugin, so responses carryAccess-Control-Allow-Origin: *with noVary: Originunlessoriginis configured to reflect/match. (cors.ts) - Widened
origin/timingOriginoption types toValue<Promisable<...>, [...]>and awaited the resolution (toArray(await value(...))), enabling async per-request resolution from the interceptor options (includingcontext). (cors.ts) - Updated default-behavior expectations and added async
originandtimingOrigintests with exact assertions. (cors.test.ts) - Documented the breaking default and the v1 restore pattern in
from-v1.mdx, and added a Dynamic Origin example plus a credentialed-wildcard warning incors.mdx.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| constructor(options: CORSHandlerPluginOptions<T> = {}) { | ||
| const defaults: CORSHandlerPluginOptions<T> = { | ||
| origin: origin => origin, | ||
| origin: '*', |
There was a problem hiding this comment.
With origin now defaulting to '*', any existing credentials: true setup that doesn't explicitly set origin will emit both Access-Control-Allow-Origin: * and Access-Control-Allow-Credentials: true on every response, which browsers reject. The docs warn, but a runtime guard would turn a silent misconfiguration into an early error. Consider throwing when credentials is combined with a wildcard origin (whether explicit or via the new default), or otherwise short-circuiting the invalid pair.

CORSHandlerPlugin now defaults
originto*instead of reflecting the request origin, and theoriginandtimingOriginoptions accept async functions so the allowed origin can be resolved per request from the handler context.Breaking
Access-Control-Allow-Origin: *with noVary: Originheader; setups relying oncredentialsmust configureoriginexplicitly (e.g.origin: origin => originrestores the v1 behavior). Documented in the v1 migration guide.Docs
*default is rejected by browsers for credentialed requests, and adds a Dynamic Origin section with an asyncoriginresolved from context.Testing
origin/timingOrigincovered by new tests; full server suite (505 tests), type check, lint, and docs validation pass.