forked from cocor-tech/moistello-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.mjs
More file actions
109 lines (103 loc) · 3.36 KB
/
Copy pathnext.config.mjs
File metadata and controls
109 lines (103 loc) · 3.36 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/** @type {import('@sentry/nextjs').withSentryConfig} */
const { withSentryConfig } = await import("@sentry/nextjs")
import { API_CSP } from "./src/lib/security/api-csp.mjs"
// Derive the backend hostname from the API URL env var so the image allowlist
// stays in sync with the deployment without hardcoding domain names here.
// Falls back to localhost for local development.
function apiHostname() {
const raw = process.env.NEXT_PUBLIC_API_URL || ""
try {
return new URL(raw).hostname
} catch {
return "localhost"
}
}
// Static CSP served on every /api/:path* response. Canonical policy lives in
// src/lib/security/api-csp.mjs so the middleware can serve the same header and
// the validation script can assert it. API routes only ever return JSON, so the
// policy is deliberately minimal — no scripts, no frames, no subresources.
const apiCsp = API_CSP
/** @type {import('next').NextConfig} */
const nextConfig = {
images: {
// Restrict to the specific hosts this application actually serves images
// from. The wildcard "**" that was here before is an SSRF vector — any
// user-supplied URL would be fetched server-side by Next.js image
// optimisation. Each entry below is a real, known source:
//
// 1. The app's own backend API (avatar / media uploads)
// 2. Cloudflare-hosted IPFS gateway (avatarIpfsHash profile pictures)
// 3. Public IPFS gateway — fallback for IPFS-pinned assets
//
// Add new entries here only when a genuine new image source is introduced.
remotePatterns: [
{
// App backend — avatar uploads, media served by the API
protocol: "https",
hostname: apiHostname(),
},
{
// Cloudflare IPFS gateway — used for avatarIpfsHash profile images
protocol: "https",
hostname: "cloudflare-ipfs.com",
pathname: "/ipfs/**",
},
{
// Public IPFS gateway — fallback for IPFS-pinned assets
protocol: "https",
hostname: "ipfs.io",
pathname: "/ipfs/**",
},
],
},
async headers() {
return [
{
source: "/api/:path*",
headers: [
{
key: "Content-Security-Policy",
value: apiCsp,
},
],
},
{
source: "/(.*)",
// Page CSP is built in src/middleware.ts because it carries a
// per-request nonce for the root layout's inline scripts. API routes
// receive the static CSP entry above. Static headers that do not vary
// per request belong below.
headers: [
{
key: "X-Frame-Options",
value: "DENY",
},
{
key: "X-Content-Type-Options",
value: "nosniff",
},
{
key: "Referrer-Policy",
value: "strict-origin-when-cross-origin",
},
{
key: "Permissions-Policy",
value: "camera=(), microphone=(), geolocation=()",
},
{
key: "Strict-Transport-Security",
value: "max-age=31536000; includeSubDomains",
},
],
},
];
},
};
export default withSentryConfig(nextConfig, {
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT,
authToken: process.env.SENTRY_AUTH_TOKEN,
silent: true,
hideSourceMaps: true,
widenClientFileUpload: true,
})