Merge pull request #16 from damjan1996/auto-claude/013-add-missing-critical-security-headers-csp-hsts-per
auto-claude: 013-add-missing-critical-security-headers-csp-hsts-per
This commit is contained in:
@@ -1,17 +1,48 @@
|
||||
<<<<<<< HEAD
|
||||
import { chain, chainMatch, isPageRequest, csp } from '@next-safe/middleware';
|
||||
=======
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
>>>>>>> origin/master
|
||||
import createMiddleware from 'next-intl/middleware';
|
||||
import { locales, defaultLocale } from './i18n/config';
|
||||
import { randomBytes } from 'crypto';
|
||||
|
||||
<<<<<<< HEAD
|
||||
const handleI18nRouting = createMiddleware({
|
||||
=======
|
||||
const CSRF_TOKEN_COOKIE_NAME = 'csrf_token';
|
||||
const CSRF_TOKEN_LENGTH = 32;
|
||||
|
||||
const intlMiddleware = createMiddleware({
|
||||
>>>>>>> origin/master
|
||||
locales,
|
||||
defaultLocale,
|
||||
localePrefix: 'always',
|
||||
});
|
||||
|
||||
<<<<<<< HEAD
|
||||
// Define CSP using @next-safe/middleware
|
||||
const securityMiddleware = csp({
|
||||
directives: {
|
||||
'default-src': ["'self'"],
|
||||
'script-src': ["'self'", "'unsafe-inline'", "'unsafe-eval'"],
|
||||
'style-src': ["'self'", "'unsafe-inline'", 'https://fonts.googleapis.com'],
|
||||
'font-src': ["'self'", 'https://fonts.gstatic.com', 'data:'],
|
||||
'img-src': ["'self'", 'data:', 'blob:', 'https://mxadgucxhmstlzsbgmoz.supabase.co'],
|
||||
'connect-src': ["'self'", 'https://mxadgucxhmstlzsbgmoz.supabase.co'],
|
||||
'frame-ancestors': ["'self'"],
|
||||
'base-uri': ["'self'"],
|
||||
'form-action': ["'self'"],
|
||||
},
|
||||
});
|
||||
|
||||
// Use chain to combine i18n middleware with security middleware
|
||||
// First run i18n, then apply CSP only on page requests
|
||||
export default chain(
|
||||
handleI18nRouting,
|
||||
chainMatch(isPageRequest)(securityMiddleware)
|
||||
);
|
||||
=======
|
||||
export default function middleware(request: NextRequest) {
|
||||
// Run the i18n middleware first
|
||||
const response = intlMiddleware(request);
|
||||
@@ -39,6 +70,7 @@ export default function middleware(request: NextRequest) {
|
||||
|
||||
return response;
|
||||
}
|
||||
>>>>>>> origin/master
|
||||
|
||||
export const config = {
|
||||
matcher: [
|
||||
|
||||
Reference in New Issue
Block a user