fix(runtime): let Studio read /.decofile from a local dev server
Merged
GU
4d ago+83+83+01234567890123456789-16-16-01234567890123456789
Problem
Studio's Local mode (site editor ā Advanced ā Local) points the CMS at a developer's own dev server and reads /.decofile from it directly in the browser. The release route (/.decofile, /live/release) only sends CORS headers when the request's origin is one of the trusted authorities (configs.decocdn.com, configs.deco.cx, admin.deco.cx, localhost). studio.decocms.com is not on that list, so Chrome blocks the response and Studio shows "Blocks unavailable" even though the dev server answered 200.
The workaround today is to start the site with DECO_ALLOWED_AUTHORITIES=...,studio.decocms.com.
Change
runtime/releaseCors.ts: when the runtime is local (Context.active().platform === "localhost": not Kubernetes, Deno Deploy or Workers), the release route also answers CORS for Studio's app origins,studio.decocms.comandstudio-stg.decocms.com, matched by exact hostname. Tunnels work too, since the requesting origin is still Studio.- Deployed runtimes are unchanged: only the trusted authorities get CORS headers.
- Studio is not added to
trustedAuthority.ts, since that list also decides where a release may be fetched from (engine/decofile/fetcher.ts). - The check lives in its own module so it can be tested without importing
middleware.ts(importingroutes/release.tsfrom a test hits a circular init).
Security notes
- Production behavior does not change.
- Locally, only Studio's origins are added. Other pages the developer opens still cannot read the local decofile.
- A runtime self-hosted outside Kubernetes/Deno Deploy/Workers (no
K_SERVICE) is detected aslocalhost, so it would answer Studio's origins too.
Verification
deno test -A runtime/releaseCors.test.ts: a local runtime allows Studio and the trusted authorities; a deployed runtime allows only the trusted authorities; other origins, lookalikes (evil.studio.decocms.com,studio.decocms.com.evil.io,admin.deco.cx.evil.io),nulland unparseable origins get nothing either way.- Platform detection:
Context.active().platformislocalhostfrom a plaindeno evalandkuberneteswithK_SERVICEset. deno fmt,deno lint,deno check live.tsclean.- Not run end to end against a site's dev server.
š¤ Generated with Claude Code
Summary by CodeRabbit
- Bug Fixes
- Updated release responses to apply origin-based access controls consistently. Local runtimes now allow requests from Studio origins, while deployed runtimes allow trusted origins only.
- Responses vary by request origin, and requests with missing, invalid, or untrusted origins receive no cross-origin access headers.