Skip to content

feat(server)!: default CORS origin to "*" and support async origin options - #1914

Merged
dinwwwh merged 4 commits into
middleapi:mainfrom
dinwwwh:claude/cors-origin-async-options-ad4f0b
Aug 22, 2026
Merged

feat(server)!: default CORS origin to "*" and support async origin options#1914
dinwwwh merged 4 commits into
middleapi:mainfrom
dinwwwh:claude/cors-origin-async-options-ad4f0b

Conversation

@dinwwwh

@dinwwwh dinwwwh commented Aug 21, 2026

Copy link
Copy Markdown
Member

CORSHandlerPlugin now defaults origin to * instead of reflecting the request origin, and the origin and timingOrigin options accept async functions so the allowed origin can be resolved per request from the handler context.

Breaking

  • The default response now carries Access-Control-Allow-Origin: * with no Vary: Origin header; setups relying on credentials must configure origin explicitly (e.g. origin: origin => origin restores the v1 behavior). Documented in the v1 migration guide.

Docs

  • CORS plugin page shows an explicit allowlist in the basic example, warns that the * default is rejected by browsers for credentialed requests, and adds a Dynamic Origin section with an async origin resolved from context.

Testing

  • Default-behavior expectations updated, async origin/timingOrigin covered by new tests; full server suite (505 tests), type check, lint, and docs validation pass.

…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.
@vercel

vercel Bot commented Aug 21, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
orpc Ready Ready Preview Aug 22, 2026 1:11am

@pkg-pr-new

pkg-pr-new Bot commented Aug 21, 2026

Copy link
Copy Markdown
More templates

@orpc/ai-sdk

npm i https://pkg.pr.new/@orpc/ai-sdk@1914

@orpc/arktype

npm i https://pkg.pr.new/@orpc/arktype@1914

@orpc/bun

npm i https://pkg.pr.new/@orpc/bun@1914

@orpc/client

npm i https://pkg.pr.new/@orpc/client@1914

@orpc/cloudflare

npm i https://pkg.pr.new/@orpc/cloudflare@1914

@orpc/contract

npm i https://pkg.pr.new/@orpc/contract@1914

@orpc/experimental-effect

npm i https://pkg.pr.new/@orpc/experimental-effect@1914

@orpc/evlog

npm i https://pkg.pr.new/@orpc/evlog@1914

@orpc/hibernation

npm i https://pkg.pr.new/@orpc/hibernation@1914

@orpc/json-schema

npm i https://pkg.pr.new/@orpc/json-schema@1914

@orpc/experimental-msw

npm i https://pkg.pr.new/@orpc/experimental-msw@1914

@orpc/nest

npm i https://pkg.pr.new/@orpc/nest@1914

@orpc/next

npm i https://pkg.pr.new/@orpc/next@1914

@orpc/node

npm i https://pkg.pr.new/@orpc/node@1914

@orpc/openapi

npm i https://pkg.pr.new/@orpc/openapi@1914

@orpc/opentelemetry

npm i https://pkg.pr.new/@orpc/opentelemetry@1914

@orpc/pinia-colada

npm i https://pkg.pr.new/@orpc/pinia-colada@1914

@orpc/pino

npm i https://pkg.pr.new/@orpc/pino@1914

@orpc/publisher

npm i https://pkg.pr.new/@orpc/publisher@1914

@orpc/ratelimit

npm i https://pkg.pr.new/@orpc/ratelimit@1914

@orpc/server

npm i https://pkg.pr.new/@orpc/server@1914

@orpc/shared

npm i https://pkg.pr.new/@orpc/shared@1914

@orpc/swr

npm i https://pkg.pr.new/@orpc/swr@1914

@orpc/tanstack-query

npm i https://pkg.pr.new/@orpc/tanstack-query@1914

@orpc/trpc

npm i https://pkg.pr.new/@orpc/trpc@1914

@orpc/valibot

npm i https://pkg.pr.new/@orpc/valibot@1914

@orpc/zod

npm i https://pkg.pr.new/@orpc/zod@1914

commit: 73d1350

@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@pullfrog pullfrog Bot 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.

ℹ️ Minor suggestion — the change is well-scoped, documented, and tested. One footgun worth a thought before merge.

Reviewed changes

  • Defaulted origin to '*' in the CORS handler plugin, so responses carry Access-Control-Allow-Origin: * with no Vary: Origin unless origin is configured to reflect/match. (cors.ts)
  • Widened origin/timingOrigin option types to Value<Promisable<...>, [...]> and awaited the resolution (toArray(await value(...))), enabling async per-request resolution from the interceptor options (including context). (cors.ts)
  • Updated default-behavior expectations and added async origin and timingOrigin tests 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 in cors.mdx.

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

constructor(options: CORSHandlerPluginOptions<T> = {}) {
const defaults: CORSHandlerPluginOptions<T> = {
origin: origin => origin,
origin: '*',

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.

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.

@codspeed-hq

codspeed-hq Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 30 untouched benchmarks


Comparing dinwwwh:claude/cors-origin-async-options-ad4f0b (4b2afb9) with main (4e59295)

Open in CodSpeed

@dinwwwh
dinwwwh merged commit 519c3f2 into middleapi:main Aug 22, 2026
8 of 9 checks passed
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.

1 participant