Skip to content

Commit 9c797d5

Browse files
author
test
committed
security: add comprehensive security headers
- X-DNS-Prefetch-Control: on - X-Frame-Options: DENY (prevents clickjacking) - X-Content-Type-Options: nosniff (prevents MIME sniffing) - X-XSS-Protection: 1; mode=block (legacy XSS protection) - Referrer-Policy: strict-origin-when-cross-origin - Permissions-Policy: disable camera/microphone/geolocation - Content-Security-Policy: strict CSP allowing WebSocket connections for blockchain nodes while blocking frame/object injection CSP allows: - WebSocket (wss:/ws:) for Polkadot node connections - Vercel analytics scripts - Google Fonts for typography
1 parent 0b5f812 commit 9c797d5

File tree

1 file changed

+64
-18
lines changed

1 file changed

+64
-18
lines changed

next.config.ts

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,103 @@
1-
import type { NextConfig } from 'next';
2-
import type { Configuration, WebpackPluginInstance } from 'webpack';
3-
import MonacoWebpackPlugin from 'monaco-editor-webpack-plugin';
1+
import type { NextConfig } from "next";
2+
import type { Configuration, WebpackPluginInstance } from "webpack";
3+
import MonacoWebpackPlugin from "monaco-editor-webpack-plugin";
4+
5+
const securityHeaders = [
6+
{
7+
key: "X-DNS-Prefetch-Control",
8+
value: "on",
9+
},
10+
{
11+
key: "X-Frame-Options",
12+
value: "DENY",
13+
},
14+
{
15+
key: "X-Content-Type-Options",
16+
value: "nosniff",
17+
},
18+
{
19+
key: "X-XSS-Protection",
20+
value: "1; mode=block",
21+
},
22+
{
23+
key: "Referrer-Policy",
24+
value: "strict-origin-when-cross-origin",
25+
},
26+
{
27+
key: "Permissions-Policy",
28+
value: "camera=(), microphone=(), geolocation=()",
29+
},
30+
{
31+
key: "Content-Security-Policy",
32+
value: [
33+
"default-src 'self'",
34+
"script-src 'self' 'unsafe-eval' 'unsafe-inline' https://cdn.vercel-insights.com https://vercel.com",
35+
"style-src 'self' 'unsafe-inline' https://fonts.googleapis.com",
36+
"font-src 'self' https://fonts.gstatic.com",
37+
"img-src 'self' data: blob: https:",
38+
"connect-src 'self' wss: ws: https:",
39+
"frame-src 'none'",
40+
"object-src 'none'",
41+
"base-uri 'self'",
42+
"form-action 'self'",
43+
"frame-ancestors 'none'",
44+
"upgrade-insecure-requests",
45+
].join("; "),
46+
},
47+
];
448

549
const nextConfig: NextConfig = {
6-
webpack: (config: Configuration, { isServer }): Configuration => {
50+
async headers() {
51+
return [
52+
{
53+
source: "/(.*)",
54+
headers: securityHeaders,
55+
},
56+
];
57+
},
58+
webpack: (config: Configuration, { isServer }): Configuration => {
759
config.module = config.module || { rules: [] };
860
config.module.rules = config.module.rules || [];
961

10-
1162
config.experiments = {
1263
...config.experiments,
1364
asyncWebAssembly: true,
1465
layers: true,
1566
};
1667

1768
if (!isServer) {
18-
1969
config.optimization = config.optimization || {};
20-
config.optimization.moduleIds = 'deterministic';
70+
config.optimization.moduleIds = "deterministic";
2171

22-
2372
config.optimization.splitChunks = config.optimization.splitChunks || {};
2473
config.optimization.splitChunks.cacheGroups =
2574
config.optimization.splitChunks.cacheGroups || {};
2675

27-
2876
config.optimization.splitChunks.cacheGroups.wasm = {
2977
test: /\.wasm$/,
30-
type: 'javascript/auto',
78+
type: "javascript/auto",
3179
enforce: true,
3280
};
3381

34-
3582
config.plugins = config.plugins || [];
3683
config.plugins.push(
3784
new MonacoWebpackPlugin({
38-
languages: ['typescript', 'javascript'],
39-
filename: 'static/[name].worker.js',
40-
}) as WebpackPluginInstance
85+
languages: ["typescript", "javascript"],
86+
filename: "static/[name].worker.js",
87+
}) as WebpackPluginInstance,
4188
);
4289
}
4390

44-
4591
config.module.rules.push({
4692
test: /\.d\.ts$/,
47-
use: 'raw-loader',
93+
use: "raw-loader",
4894
});
4995

5096
return config;
5197
},
5298
poweredByHeader: false,
5399
reactStrictMode: true,
54-
output: 'standalone',
100+
output: "standalone",
55101
};
56102

57-
export default nextConfig;
103+
export default nextConfig;

0 commit comments

Comments
 (0)