fix(cors): allow loopback origins + deny cleanly instead of 500#1
Open
tmlxrd wants to merge 1 commit into
Open
fix(cors): allow loopback origins + deny cleanly instead of 500#1tmlxrd wants to merge 1 commit into
tmlxrd wants to merge 1 commit into
Conversation
The CORS origin callback called cb(new Error()) for any origin not in ALLOWED_ORIGINS, which makes the cors middleware forward to next(err) → a 500 on the OPTIONS preflight (the browser just reports "Failed to fetch"). And iClaw is local-first: the desktop app and the npx build POST from http://127.0.0.1:<port> with an ephemeral port that can't be enumerated in a static allow-list — so every share upload hit that 500. Accept any loopback HTTP origin (127.0.0.1 / localhost / [::1], any port) — the Origin header is browser-set and the share API only stores opaque ciphertext — and deny other origins with cb(null, false), a clean CORS denial (no 500). Verified: OPTIONS → 204 + ACAO for loopback & allow-listed origins; clean deny (no ACAO, no 500) for others; typecheck clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Problem
The CORS
origincallback calledcb(new Error())for any origin not inALLOWED_ORIGINS, which makes thecorsmiddleware forward tonext(err)→ a 500 on the OPTIONS preflight. Browsers surface that as a useless "Failed to fetch".And iClaw is local-first: the desktop app and the
npxbuild POST share ciphertext fromhttp://127.0.0.1:<ephemeral-port>, which can't be enumerated in a static allow-list — so every chat-share upload hit that 500.Fix
127.0.0.1/localhost/[::1], any port). TheOriginheader is browser-set (can't be forged cross-site) and the share API only ever stores opaque ciphertext.cb(null, false)— a clean CORS denial, no 500.Verified
Live test against the real
corspackage:204+Access-Control-Allow-Origin✅204+ ACAO ✅ (unchanged)tsc --noEmitclean.🤖 Generated with Claude Code