Skip to content

Commit

Permalink
Removed unusable nonce because of current bug vercel/next.js/issues/5…
Browse files Browse the repository at this point in the history
…5638. Tested on prod and dev
  • Loading branch information
yelodevopsi committed Sep 25, 2023
1 parent 070b891 commit ae8b801
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions frontend/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import { NextRequest, NextResponse } from 'next/server'

// nonce CSP is currently disabled because of bug:
// https://github.com/vercel/next.js/issues/55638

export function middleware(request: NextRequest) {
const nonce = Buffer.from(crypto.randomUUID()).toString('base64')
const cspHeader = `
default-src 'self';
script-src 'self' 'nonce-${nonce}';
script-src 'self' 'unsafe-inline' http://localhost https: ${process.env.NODE_ENV === 'production' ? '' : `'unsafe-eval'`};
style-src 'self' 'unsafe-inline';
font-src 'self' anima-uploads.s3.amazonaws.com fonts.gstatic.com;
connect-src 'self' https://login.microsoftonline.com;
`
const requestHeaders = new Headers(request.headers)
requestHeaders.set('x-nonce', nonce)

// requestHeaders.set('x-nonce', nonce)
requestHeaders.set(
'Content-Security-Policy',
// 'Content-Security-Policy',
'Content-Security-Policy-Report-Only', // This is used for now to not break

// Replace newline characters and spaces
cspHeader.replace(/\s{2,}/g, ' ').trim()
)
Expand Down

0 comments on commit ae8b801

Please sign in to comment.