/** * Findings: S-06 (security headers), S-07 (image optimiser scope), P-03 (canonical host) * * Roll-out plan for CSP: * 1. Ship with CSP_MODE=report-only and watch the browser console / report endpoint for a week. * 2. Add any legitimate sources you discover (analytics, Turnstile, fonts). * 3. Flip to CSP_MODE=enforce. * * This static CSP keeps pages cacheable. `'unsafe-inline'` for scripts is needed by Next.js * inline bootstrapping unless you adopt nonces via middleware, which forces dynamic rendering * on every page. For a mostly static marketing site, static CSP + strict other directives is * the better trade-off; revisit nonces for the authenticated product apps. */ import type { NextConfig } from "next"; const isDev = process.env.NODE_ENV !== "production"; const csp = [ `default-src 'self'`, `script-src 'self' 'unsafe-inline' https://challenges.cloudflare.com${isDev ? " 'unsafe-eval'" : ""}`, `style-src 'self' 'unsafe-inline' https://fonts.googleapis.com`, `font-src 'self' https://fonts.gstatic.com`, `img-src 'self' data: blob: https://images.unsplash.com`, `connect-src 'self' https://challenges.cloudflare.com`, `frame-src https://challenges.cloudflare.com`, // Turnstile widget `frame-ancestors 'none'`, // nobody may frame the application form (clickjacking) `form-action 'self'`, // forms can only post back to cynbit.in `base-uri 'self'`, `object-src 'none'`, `upgrade-insecure-requests`, ].join("; "); const cspHeader = process.env.CSP_MODE === "enforce" ? "Content-Security-Policy" : "Content-Security-Policy-Report-Only"; const securityHeaders = [ { key: cspHeader, value: csp }, // Two years, all subdomains. Submit to hstspreload.org once every subdomain serves HTTPS. { key: "Strict-Transport-Security", value: "max-age=63072000; includeSubDomains; preload" }, { key: "X-Content-Type-Options", value: "nosniff" }, { key: "Referrer-Policy", value: "strict-origin-when-cross-origin" }, { key: "X-Frame-Options", value: "DENY" }, // legacy browsers; frame-ancestors covers modern ones { key: "Permissions-Policy", value: "camera=(), microphone=(), geolocation=(), payment=(), usb=(), interest-cohort=()" }, { key: "Cross-Origin-Opener-Policy", value: "same-origin" }, ]; const config: NextConfig = { poweredByHeader: false, // drop "X-Powered-By: Next.js"; free, removes a fingerprint images: { // Only Unsplash photo paths can be resized. A wildcard here turns /_next/image into a // free, public image proxy billed to Cynbit. remotePatterns: [{ protocol: "https", hostname: "images.unsplash.com", pathname: "/photo-**" }], deviceSizes: [640, 960, 1280, 1920], imageSizes: [64, 128, 256], formats: ["image/avif", "image/webp"], minimumCacheTTL: 60 * 60 * 24 * 30, }, async headers() { return [ { source: "/:path*", headers: securityHeaders }, // API responses carry personal data: never cache, never sniff. { source: "/api/:path*", headers: [{ key: "Cache-Control", value: "no-store" }] }, ]; }, async redirects() { // One canonical host. (On Vercel, prefer the domain-level redirect in project settings.) return [ { source: "/:path*", has: [{ type: "host", value: "cynbit.in" }], destination: "https://www.cynbit.in/:path*", permanent: true, // 308 }, ]; }, }; export default config;