Skip to content

Fix CORS_ORIGIN wildcard patterns on Vercel deployments#1177

Merged
xuyushun441-sys merged 1 commit intomainfrom
copilot/update-cors-origin-environment-variable
Apr 17, 2026
Merged

Fix CORS_ORIGIN wildcard patterns on Vercel deployments#1177
xuyushun441-sys merged 1 commit intomainfrom
copilot/update-cors-origin-environment-variable

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 17, 2026

Setting CORS_ORIGIN="https://*.objectui.org,https://*.objectstack.ai,http://localhost:*" caused browser CORS errors on Vercel, even though the same value worked behind the Hono plugin's cors() middleware.

Root cause

apps/server/server/index.ts short-circuits OPTIONS preflight before the Hono app runs (so cold starts / bootstrap failures can't strip CORS headers). Its resolveAllowOrigin() matched with a literal Array.includes(requestOrigin)* was treated as a plain character, so every preflight from a real subdomain returned 204 with no Access-Control-Allow-Origin, blocking all subsequent requests.

const allowed = ["https://*.objectui.org", ...];
allowed.includes("https://app.objectui.org"); // false → null → browser blocks

The Hono middleware already implemented wildcard matching correctly, but the Vercel bypass path had a divergent, exact-match-only implementation.

Changes

  • Single source of truth for origin matching — extracted matchOriginPattern / createOriginMatcher / hasWildcardPattern / normalizeOriginPatterns into packages/plugins/plugin-hono-server/src/pattern-matcher.ts and exported from the package entry.
  • hono-plugin.ts — removed inline copies, imports from the shared module.
  • apps/server/server/index.tsresolveAllowOrigin() now delegates to createOriginMatcher / hasWildcardPattern when CORS_ORIGIN contains *, so the Vercel preflight short-circuit and the Hono middleware have identical semantics.
  • Testspattern-matcher.test.ts now imports the real module (no inline duplicate) and adds coverage for hasWildcardPattern, normalizeOriginPatterns, and empty-origin handling.

…t short-circuit

Agent-Logs-Url: https://github.com/objectstack-ai/framework/sessions/4eda94c5-dea3-49b4-9f32-f9d97a0d7045

Co-authored-by: xuyushun441-sys <255036401+xuyushun441-sys@users.noreply.github.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 17, 2026

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

Project Deployment Actions Updated (UTC)
objectstack-demo Ready Ready Preview, Comment Apr 17, 2026 9:43am
spec Ready Ready Preview, Comment Apr 17, 2026 9:43am

Request Review

@xuyushun441-sys xuyushun441-sys marked this pull request as ready for review April 17, 2026 09:44
@xuyushun441-sys xuyushun441-sys merged commit 9b07089 into main Apr 17, 2026
3 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.

2 participants