Repository navigation
fix(nginx): serve /studio-modules/ with CORS, no SPA fallback - #8420
Merged
Merged
Conversation
The v8 editor modules (wireframe.js, html-swap.js) are imported by the site page from Studio cross-origin. #8379 added the CORS header in the Bun API, but in production nginx serves the static files, so /studio-modules/ fell into "location /": no Access-Control-Allow-Origin, frame headers, and index.html for a missing file. Give it its own location: ACAO *, no-cache without validators (ETag off, Last-Modified cleared, If-Modified-Since ignored -- filenames are not hashed and build mtimes are pinned), nosniff, and a no-store 404 on a miss. Co-Authored-By: Claude Opus 5.5 <[email protected]>
tlgimenes
marked this pull request as ready for review
November 10, 2026 14:40
decocms Bot
pushed a commit
that referenced
this pull request
Nov 10, 2026
PR: #8420 fix(nginx): serve /studio-modules/ with CORS, no SPA fallback Bump type: patch - decocms (apps/api/package.json): 4.560.4 -> 4.560.5 Deploy-Scope: both
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Not merged — waiting for review.
Summary
A Blocks v8 site page (for example osklen, deco-sites/osklenbr-faststore#1388) loads Studio's editor modules (
/studio-modules/v1/wireframe.js,html-swap.js) with a cross-originimport()after Studio sendsdeco:load. #8379 addedAccess-Control-Allow-Originin the Bun API (withStudioModulesCors), but in the deployed image nginx serves the static files, so the request never reaches Bun./studio-modules/falls intolocation /and gets no ACAO header, getsX-Frame-Options: DENYand the frame CSP, and gets the SPA'sindex.html(200) for a file that does not exist. Today, in production and staging, the browser blocks the import:This PR adds
location ^~ /studio-modules/todeploy/helm/studio/files/api-nginx.conf:Access-Control-Allow-Origin: *(public static code, fetched without credentials)Cache-Control: no-cache, with no validators:etag off,if_modified_since off, andLast-Modifiedcleared. The filenames are not content-hashed, and pinned build mtimes make ETag and Last-Modified the same across deploys, so a validator could 304 against a stale copy.X-Content-Type-Options: nosniff. No frame headers, because they only apply to documents.404withno-storeand ACAO, never the SPA fallback.It also adds a note to
deploy/nginx/README.md.Decisions taken
no-cache(decided by the user), the same as the dev server. Revalidating on every import is cheap for two small files, and it means the editor always runs the module of the pod it is talking to.*rather than an origin allow-list. The files are public, uncredentialed scripts, and site origins are open-ended (custom domains, preview hosts).Before production can use this
/studio-modules/v1/wireframe.jswithcache-control: max-age=14400(server: cloudflare,cf-cache-status: MISS). That is a Cloudflare edge or browser-TTL rule, not this nginx config. With it in place, browsers can keep a module for 4h after a deploy. Whoever owns the Cloudflare config for studio(-stg).decocms.com should know this. A cache rule for/studio-modules/*that respects origin headers is the likely fix. This PR does not touch Cloudflare.apps/web/Dockerfile), so it takes effect only after a release and a tag bump in deploy.How to spike it
The local nginx container uses the image from
apps/web/Dockerfile,nginxinc/nginx-unprivileged:1.27-alpine, with this branch'sapi-nginx.confas the template and the builtstudio-modules/v1/*.jsplus a stub SPA in/usr/share/nginx/html:Then run a Playwright page on another origin (
http://127.0.0.1:18090) that callsimport()on the module URLs.Evidence
I spiked head
d689dbdwith thenginxinc/nginx-unprivileged:1.27-alpineimage, the builtwireframe.jsandhtml-swap.js(pinned 1985 mtimes), and a stub SPA. The container started, so the config loads./studio-modules/v1/wireframe.js?build=x200,application/javascript,ACAO: *,Cache-Control: no-cache,nosniff. No ETag, no Last-Modified, no X-Frame-Options, no CSP./studio-modules/v1/html-swap.jswireframe.js./studio-modules/v1/nope.js404,ACAO: *,Cache-Control: no-store. Not the SPA'sindex.html./studio-modules/v1/wireframe.jswithIf-Modified-Since: <file mtime>200, not304./assets/index-abc123.js/some/route(SPA)no-cache,X-Frame-Options: DENY,frame-ancestors 'none'.I also ran a cross-origin
import()with Playwright Chromium from a page onhttp://127.0.0.1:18090:wireframe.jsandhtml-swap.jssuccessfully (ok: true, 1 export each).blocked by CORS policy: No 'Access-Control-Allow-Origin' header.Known limitations
max-age=14400override (above) still applies until someone changes the edge rule.🤖 Generated with Claude Code
Summary by cubic
Fixes cross-origin loading of Studio's editor modules from Blocks v8 site pages. Previously nginx served
/studio-modules/through the default location, which lacked anAccess-Control-Allow-Originheader and fell back to the SPA'sindex.htmlfor missing files, so browsers blocked the modules'import(). The newlocation ^~ /studio-modules/answers withAccess-Control-Allow-Origin: *,no-cache(with ETag, Last-Modified, and If-Modified-Since disabled, since filenames are not content-hashed and build mtimes are pinned), andnosniff, and returns ano-store404 for missing modules instead of the SPA fallback.Deployment notes
/studio-modules/*(browsers can cache a module for 4h); a Cloudflare cache rule respecting origin headers is needed for correct post-deploy behavior.Written for commit d689dbd. Summary will update on new commits.