Skip to content

Commit 9c7074d

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 9c7074d

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

services/gastown/src/gastown.worker.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,14 @@ 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.
270+
271+
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;
270272

271273
const corsMiddleware = cors({
272274
origin: (origin, c: Context<GastownEnv>) => {
273275
if (c.env.ENVIRONMENT === 'development') {
274-
// Allow any localhost origin in dev
275-
if (origin.startsWith('http://localhost:')) return origin;
276+
if (localIpPattern.test(origin)) return origin;
276277
}
277278
// Production origins
278279
const allowed = ['https://app.kilo.ai', 'https://kilo.ai'];

services/wasteland/src/wasteland.worker.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,14 @@ 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.
93+
94+
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;
9395

9496
const corsMiddleware = cors({
9597
origin: (origin, c: Context<WastelandEnv>) => {
9698
if (c.env.ENVIRONMENT === 'development') {
97-
if (origin.startsWith('http://localhost:')) return origin;
99+
if (localIpPattern.test(origin)) return origin;
98100
}
99101
const allowed = ['https://app.kilo.ai', 'https://kilo.ai'];
100102
return allowed.includes(origin) ? origin : '';

0 commit comments

Comments
 (0)