Repository navigation
Expand file tree
/
Copy pathnext.config.ts
More file actions
58 lines (53 loc) · 2.59 KB
/
Copy pathnext.config.ts
File metadata and controls
58 lines (53 loc) · 2.59 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
import type { NextConfig } from "next";
import path from "node:path";
const isProd = process.env.NODE_ENV === "production";
/**
* Content-Security-Policy (K13.9). Wallets run in `srcdoc` sandbox frames, which inherit this policy,
* and wallet sign-in can't be tested without a real wallet. So only directives that can't touch
* wallet code are enforced; the full policy is report-only (violations show in the browser console)
* until a real-wallet sign-in shows none, then it moves to the enforced header.
*/
const CSP_ENFORCED = ["object-src 'none'", "frame-ancestors 'none'"].join("; ");
const CSP_REPORT_ONLY = [
"default-src 'self'",
// Next.js inlines its bootstrap scripts; dev mode also needs eval for fast refresh.
`script-src 'self' 'unsafe-inline'${isProd ? "" : " 'unsafe-eval'"}`,
"style-src 'self' 'unsafe-inline'",
"img-src 'self' data: blob:",
"font-src 'self' data:",
"media-src 'self'",
// The wallet connector fetches its wallet list and talks to wallets and NEAR RPC over https/wss.
"connect-src 'self' https: wss:",
"frame-src 'self'",
"object-src 'none'",
"base-uri 'self'",
"form-action 'self'",
"frame-ancestors 'none'",
].join("; ");
/** Baseline security headers (K8.7, K13.9). */
const securityHeaders = [
{ key: "Content-Security-Policy", value: CSP_ENFORCED },
{ key: "Content-Security-Policy-Report-Only", value: CSP_REPORT_ONLY },
{ key: "X-Content-Type-Options", value: "nosniff" },
{ key: "X-Frame-Options", value: "DENY" },
{ key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
{ key: "Permissions-Policy", value: "camera=(), microphone=(), geolocation=(), payment=()" },
// Wallet sign-in may use popups that need to talk back to this window.
{ key: "Cross-Origin-Opener-Policy", value: "same-origin-allow-popups" },
...(isProd ? [{ key: "Strict-Transport-Security", value: "max-age=31536000; includeSubDomains" }] : []),
];
const nextConfig: NextConfig = {
reactStrictMode: true,
poweredByHeader: false,
// This folder is the project root, even if a stray lockfile exists higher up on the machine.
outputFileTracingRoot: path.resolve(import.meta.dirname),
// Migrations are read from disk at runtime (db.migrate()); serverless bundles only include imported
// files, so ship the SQL explicitly.
outputFileTracingIncludes: { "/api/**/*": ["./drizzle/**/*"] },
// PGlite loads its WebAssembly via import.meta.url; bundling breaks that, so Node loads it directly.
serverExternalPackages: ["@electric-sql/pglite"],
async headers() {
return [{ source: "/:path*", headers: securityHeaders }];
},
};
export default nextConfig;