Skip to content

Commit 8eaa298

Browse files
committed
chore(cors): broaden local origin matching for dev environments
The previous localhost-only prefix check caused CORS failures when developers accessed the dev server via LAN IP (10.x, 172.16-31.x, 192.168.x), loopback (127.x), or IPv6 link-local/ULA addresses. This was common when using mobile devices on the same LAN for testing or when tunneling into the dev environment. Both gastown and wasteland were updated to use the same regex so they stay in sync. ## Summary - services/gastown/src/gastown.worker.ts - services/wasteland/src/wasteland.worker.ts
1 parent 3b86a63 commit 8eaa298

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

services/gastown/src/gastown.worker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,13 @@ app.use('/api/mayor/:townId/tools/rigs/:rigId/agents/:agentId/*', async (c, next
266266

267267
// ── CORS ────────────────────────────────────────────────────────────────
268268
// Allow browser requests from the main Kilo app. In development, allow
269-
// localhost origins for the Next.js dev server.
269+
// localhost and LAN origins for the Next.js dev server.
270270

271271
const corsMiddleware = cors({
272272
origin: (origin, c: Context<GastownEnv>) => {
273273
if (c.env.ENVIRONMENT === 'development') {
274-
// Allow any localhost origin in dev
275-
if (origin.startsWith('http://localhost:')) return origin;
274+
const localIpPattern = /^https?:\/\/(localhost|127\.\d+\.\d+\.\d+|10\.\d+\.\d+\.\d+|172\.(1[6-9]|2[0-9]|3[0-1])\.\d+\.\d+|192\.168\.\d+\.\d+|\[(::1|fd[0-9a-f]{2}:[0-9a-f:]+|fe80:[0-9a-f:]+)\])(:\d+)?$/i;
275+
if (localIpPattern.test(origin)) return origin;
276276
}
277277
// Production origins
278278
const allowed = ['https://app.kilo.ai', 'https://kilo.ai'];

services/wasteland/src/wasteland.worker.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,13 @@ app.use('*', async (c, next) => {
8989

9090
// ── CORS ────────────────────────────────────────────────────────────────
9191
// Allow browser requests from the main Kilo app. In development, allow
92-
// localhost origins for the Next.js dev server.
92+
// localhost and LAN origins for the Next.js dev server.
9393

9494
const corsMiddleware = cors({
9595
origin: (origin, c: Context<WastelandEnv>) => {
9696
if (c.env.ENVIRONMENT === 'development') {
97-
if (origin.startsWith('http://localhost:')) return origin;
97+
const localIpPattern = /^https?:\/\/(localhost|127\.\d+\.\d+\.\d+|10\.\d+\.\d+\.\d+|172\.(1[6-9]|2[0-9]|3[0-1])\.\d+\.\d+|192\.168\.\d+\.\d+|\[(::1|fd[0-9a-f]{2}:[0-9a-f:]+|fe80:[0-9a-f:]+)\])(:\d+)?$/i;
98+
if (localIpPattern.test(origin)) return origin;
9899
}
99100
const allowed = ['https://app.kilo.ai', 'https://kilo.ai'];
100101
return allowed.includes(origin) ? origin : '';

0 commit comments

Comments
 (0)