-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.ts
More file actions
88 lines (82 loc) · 3.16 KB
/
Copy pathnext.config.ts
File metadata and controls
88 lines (82 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import type { NextConfig } from "next";
import { getBrandProfile, getInventoryIntegration } from "./src/config/brand";
const enableTweakcnPreview = process.env.VERCEL !== "1";
const speedInsightsScriptHost = "https://va.vercel-scripts.com";
const speedInsightsConnectHost = "https://vitals.vercel-insights.com";
const brandProfile = getBrandProfile(process.env.NEXT_PUBLIC_LOTTO_BRAND);
const inventoryIntegration = getInventoryIntegration(brandProfile);
const feedPublicInventoryHost = inventoryIntegration.url
? new URL(inventoryIntegration.url).origin
: null;
const scriptSrc = enableTweakcnPreview
? `script-src 'self' 'unsafe-inline' ${speedInsightsScriptHost} https://tweakcn.com https://*.tweakcn.com`
: `script-src 'self' 'unsafe-inline' ${speedInsightsScriptHost}`;
const connectSrcHosts = [
"'self'",
speedInsightsConnectHost,
speedInsightsScriptHost,
feedPublicInventoryHost,
...(enableTweakcnPreview ? ["https://tweakcn.com", "https://*.tweakcn.com"] : []),
].filter(Boolean);
const connectSrc = `connect-src ${connectSrcHosts.join(" ")}`;
const frameAncestors = enableTweakcnPreview
? "frame-ancestors 'self' https://tweakcn.com https://*.tweakcn.com"
: "frame-ancestors 'none'";
const nextConfig: NextConfig = {
productionBrowserSourceMaps: false,
// Uploaded brand logos may be SVGs (kept vector for crisp hi-DPI
// rendering). next/image refuses SVG sources unless explicitly allowed;
// the paired CSP sandboxes every optimizer response so an SVG document can
// never script, and uploads are already validated self-contained by
// src/lib/brand-config/assets.ts.
images: {
dangerouslyAllowSVG: true,
contentSecurityPolicy: "default-src 'none'; style-src 'unsafe-inline'; sandbox;",
},
turbopack: {},
webpack: (config, { isServer, dev }) => {
if (isServer && !dev && !process.env.DATABASE_URL) {
throw new Error("DATABASE_URL is required for production builds.");
}
return config;
},
async headers() {
return [
{
source: "/(.*)",
headers: [
{
key: "Content-Security-Policy",
value: [
"default-src 'self'",
scriptSrc,
"style-src 'self' 'unsafe-inline'",
"img-src 'self' data: blob:",
"font-src 'self'",
connectSrc,
frameAncestors,
"base-uri 'self'",
"form-action 'self'",
].join("; "),
},
],
},
{
// Stored brand assets may be operator-uploaded SVG documents. They
// are validated inert at upload (src/lib/brand-config/assets.ts);
// this stricter CSP is defense in depth so a directly-navigated SVG
// can never script or load anything, even if validation were ever
// bypassed. Last matching rule wins for the same header key, so this
// overrides the site-wide policy above for assets only.
source: "/api/brand-assets/:path*",
headers: [
{
key: "Content-Security-Policy",
value: "default-src 'none'; style-src 'unsafe-inline'; sandbox",
},
],
},
];
},
};
export default nextConfig;