diff --git a/web/next.config.ts b/web/next.config.ts index 433c34c..58d5b65 100644 --- a/web/next.config.ts +++ b/web/next.config.ts @@ -1,5 +1,25 @@ import type { NextConfig } from "next"; +const apiOrigin = (() => { + try { + return new URL( + process.env.NEXT_PUBLIC_API_URL ?? "http://127.0.0.1:8000", + ).origin; + } catch { + return "http://127.0.0.1:8000"; + } +})(); + +const csp = [ + "default-src 'self'", + "script-src 'self' 'unsafe-inline'", + "style-src 'self' 'unsafe-inline'", + "img-src 'self' data: https:", + "font-src 'self' data:", + `connect-src 'self' ${apiOrigin} https://*.supabase.co`, + "frame-ancestors 'none'", +].join("; "); + const securityHeaders = [ { key: "X-Frame-Options", value: "DENY" }, { key: "X-Content-Type-Options", value: "nosniff" }, @@ -12,11 +32,7 @@ const securityHeaders = [ key: "Strict-Transport-Security", value: "max-age=63072000; includeSubDomains", }, - { - key: "Content-Security-Policy-Report-Only", - value: - "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self' data:; connect-src 'self' https://lysis-3ocq.onrender.com https://*.supabase.co; frame-ancestors 'none'", - }, + { key: "Content-Security-Policy", value: csp }, ]; const nextConfig: NextConfig = { @@ -35,4 +51,4 @@ const nextConfig: NextConfig = { }, }; -export default nextConfig; +export default nextConfig; \ No newline at end of file