mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
fix(cors): reflect origin for WebView routes using Bearer auth
Routes prefixed with /api/opencode-proxy/ and /api/internal/ authenticate via Bearer/CF-Access headers rather than cookies. These routes are now allowed to reflect any origin in the CORS response since they don't rely on cookie-based trust. Also added CF-Access-Client-Id and CF-Access-Client-Secret to the allowed headers list.
This commit is contained in:
1 parent
5d9a159c07
commit
7c7e9f3c77
1 file changed
+12
-2
+12
-2
@@ -78,15 +78,25 @@ const DB_PATH = getDatabasePath()
|
||||
|
||||
const app = new Hono()
|
||||
|
||||
/**
|
||||
* Route prefixes reachable from custom WebViews whose origin is not a
|
||||
* trusted web origin (e.g. "null" for file://). These routes authenticate via
|
||||
* Bearer/CF-Access headers rather than cookies, so any origin may be reflected.
|
||||
*/
|
||||
const REFLECT_ANY_ORIGIN_PREFIXES = ['/api/opencode-proxy/', '/api/internal/']
|
||||
|
||||
app.use('/*', cors({
|
||||
origin: (origin) => {
|
||||
origin: (origin, c) => {
|
||||
if (origin && REFLECT_ANY_ORIGIN_PREFIXES.some(prefix => c.req.path.startsWith(prefix))) {
|
||||
return origin
|
||||
}
|
||||
const trustedOrigins = ENV.AUTH.TRUSTED_ORIGINS.split(',').map(o => o.trim())
|
||||
if (!origin) return trustedOrigins[0]
|
||||
if (trustedOrigins.includes(origin)) return origin
|
||||
return trustedOrigins[0]
|
||||
},
|
||||
allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
|
||||
allowHeaders: ['Content-Type', 'Authorization'],
|
||||
allowHeaders: ['Content-Type', 'Authorization', 'CF-Access-Client-Id', 'CF-Access-Client-Secret'],
|
||||
credentials: true,
|
||||
}))
|
||||
|
||||
|
||||
Reference in new issue
Block a user