Files
parsaaghayi-front/next.config.mjs
T
root 6a56b27b01 Add security headers and make the contact form actually submit
The contact section collected input and discarded it on submit.

There is no backend contact endpoint and no mail provider, so the form opens
the visitor's mail client with a prefilled Persian subject and body. Validation
is client-side with inline Persian errors, an accessible alert summary, and
focus moved to the first invalid field; a persistent hint states up front that
nothing is stored on the server and shows the address to copy if no mail
client is registered.

Also add the response headers the site was missing: HSTS, nosniff, frame
denial, a strict referrer policy, a restrictive permissions policy, and a CSP.
The CSP still needs 'unsafe-inline' for scripts because nonces are not
implemented yet; that is the next hardening step. poweredByHeader is off so
the framework is not advertised.
2026-10-01 16:33:20 -04:00

122 lines
3.7 KiB
JavaScript

import withBundleAnalyzer from '@next/bundle-analyzer';
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'standalone',
reactStrictMode: false,
poweredByHeader: false,
turbopack: {},
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'via.placeholder.com',
port: '',
pathname: '/**',
},
{
protocol: 'https',
hostname: 'backend.parsaaghayi.ir',
port: '',
pathname: '/**',
},
{
protocol: 'https',
hostname: 'parsaaghayi.ir',
port: '',
pathname: '/**',
},
],
},
async rewrites() {
return [
{
source: '/api/website/:path*',
destination: `${process.env.NEXT_PUBLIC_BACK_URL}/api/website/:path*`,
},
{
source: '/api/blog/:path*',
destination: `${process.env.NEXT_PUBLIC_BACK_URL}/api/blog/:path*`,
},
];
},
async headers() {
// `upgrade-insecure-requests` is a CSP directive, not a header, so it lives inside
// the policy value below. `connect-src` allows the production backend only; the dev
// API runs on plain http://localhost:8000 (see .env.development), so that origin is
// appended outside of production to keep `next dev` working.
const connectSrc = ["'self'", 'https://backend.parsaaghayi.ir'];
if (process.env.NODE_ENV === 'development') {
connectSrc.push('http://localhost:8000', 'http://127.0.0.1:8000');
}
// TODO follow-up: ship a nonce-based policy (`script-src 'nonce-<random>'` plus
// `'strict-dynamic'`). `'unsafe-inline'` is still required for scripts because
// Next.js emits inline bootstrap scripts (hydration payload, next-themes script)
// and framer-motion/next-themes are not wired up to receive a nonce yet. The nonce
// can be threaded through the root layout + middleware, which is what lets us drop
// `'unsafe-inline'` from script-src.
const contentSecurityPolicy = [
"default-src 'self'",
"script-src 'self' 'unsafe-inline'",
"style-src 'self' 'unsafe-inline'",
"img-src 'self' data: blob: https:",
"font-src 'self' data:",
`connect-src ${connectSrc.join(' ')}`,
"media-src 'self' blob:",
"object-src 'none'",
"base-uri 'self'",
"frame-ancestors 'none'",
"form-action 'self'",
'upgrade-insecure-requests',
].join('; ');
return [
{
source: '/:path*',
headers: [
{
key: 'Strict-Transport-Security',
value: 'max-age=63072000; includeSubDomains; preload',
},
{ 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=(), interest-cohort=()',
},
{ key: 'Content-Security-Policy', value: contentSecurityPolicy },
],
},
];
},
webpack(config, { isServer }) {
if (!isServer) {
config.optimization.splitChunks = {
chunks: 'all',
minSize: 30000,
maxAsyncRequests: 30,
maxInitialRequests: 30,
automaticNameDelimiter: '-',
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
},
},
};
}
return config;
},
};
const withBundle = withBundleAnalyzer({
enabled: process.env.ANALYZE === 'true',
// می‌توانید تنظیمات اضافی پلاگین را اینجا اضافه کنید
})(nextConfig);
export default withBundle;