Skip to content

Commit 86b13eb

Browse files
chore(frontend): add CSP in next config (#85)
* Add security headers to frontend * rm unsafe directives * re-add unsafe directives, staging backend url * fix json format * add trailing comma * chore(frontend): improve CSP per Next.js docs * style(frontend): standardize quotes for upgrade-insecure-requests header --------- Co-authored-by: Madhur Gupta <madhurgupta107@gmail.com>
1 parent 19e46e9 commit 86b13eb

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

frontend/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ NEXT_PUBLIC_EVENTS_WS_URL="wss://<SERVER_ADDR>:<SERVER_PORT>"
33

44
# BlockVision Pro API key for Monad mainnet contract metadata lookups
55
# Get your API key from https://docs.blockvision.org/
6-
BLOCKVISION_API_KEY="your-api-key-here"
6+
BLOCKVISION_API_KEY="your-api-key-here"

frontend/next.config.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { NextConfig } from 'next'
22

3+
const isDev = process.env.NODE_ENV === 'development'
4+
35
const nextConfig: NextConfig = {
46
images: {
57
remotePatterns: [
@@ -10,6 +12,38 @@ const nextConfig: NextConfig = {
1012
},
1113
],
1214
},
15+
async headers() {
16+
return [
17+
{
18+
source: '/(.*)',
19+
headers: [
20+
{ key: 'X-Content-Type-Options', value: 'nosniff' },
21+
{ key: 'Referrer-Policy', value: 'strict-origin-when-cross-origin' },
22+
{
23+
key: 'Permissions-Policy',
24+
value: 'geolocation=(), microphone=(), camera=()',
25+
},
26+
{ key: 'X-Frame-Options', value: 'DENY' },
27+
{
28+
key: 'Content-Security-Policy',
29+
value: [
30+
"default-src 'self'",
31+
`script-src 'self' 'unsafe-inline' https://va.vercel-scripts.com${isDev ? " 'unsafe-eval'" : ''}`,
32+
"style-src 'self' 'unsafe-inline'",
33+
"img-src 'self' data: https://raw.githubusercontent.com",
34+
"font-src 'self'",
35+
"connect-src 'self' wss://monode-mainnet.monadinfra.com wss://execution-events-backend-example.molandak.org",
36+
"frame-ancestors 'none'",
37+
"object-src 'none'",
38+
"base-uri 'self'",
39+
"form-action 'self'",
40+
'upgrade-insecure-requests',
41+
].join('; '),
42+
},
43+
],
44+
},
45+
]
46+
},
1347
}
1448

1549
export default nextConfig

0 commit comments

Comments
 (0)