mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-24 11:01:16 +00:00
fix: gate permissive CORS to dev only
In production, only origins listed in CORS_ORIGINS env var are allowed. In dev, any origin is reflected back. Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
@@ -51,10 +51,18 @@ function main() {
|
|||||||
|
|
||||||
const app = new Hono()
|
const app = new Hono()
|
||||||
|
|
||||||
|
const isDev = process.env.NODE_ENV !== "production"
|
||||||
|
const allowedOrigins = process.env.CORS_ORIGINS?.split(",").map((o) => o.trim()) ?? []
|
||||||
|
|
||||||
|
function resolveOrigin(origin: string): string | undefined {
|
||||||
|
if (isDev) return origin
|
||||||
|
return allowedOrigins.includes(origin) ? origin : undefined
|
||||||
|
}
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
"/api/auth/*",
|
"/api/auth/*",
|
||||||
cors({
|
cors({
|
||||||
origin: (origin) => origin,
|
origin: resolveOrigin,
|
||||||
allowHeaders: ["Content-Type", "Authorization"],
|
allowHeaders: ["Content-Type", "Authorization"],
|
||||||
allowMethods: ["POST", "GET", "OPTIONS"],
|
allowMethods: ["POST", "GET", "OPTIONS"],
|
||||||
exposeHeaders: ["Content-Length"],
|
exposeHeaders: ["Content-Length"],
|
||||||
@@ -66,7 +74,7 @@ function main() {
|
|||||||
app.use(
|
app.use(
|
||||||
"*",
|
"*",
|
||||||
cors({
|
cors({
|
||||||
origin: (origin) => origin,
|
origin: resolveOrigin,
|
||||||
credentials: true,
|
credentials: true,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user