You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
export const config = {
matcher: [
'/(.*)',
'/', // explicit matcher for root route
],
}
`
2. Run the application on local dev using npm run dev. Test and you'll see it works fine. Open network tab in dev tools and check the response. All scripts, have the nonce added on local dev.
Deploy your sample application to AWS amplify. You will get a white screen or screen with no content with errors in console in devTools. I have attached screenshot of error.
Current vs. Expected behavior
I expect the web app to load well without issues since CSP addition is done by middleware. But, what I get is a blank screen with an error. This error.
Link to the code that reproduces this issue
https://github.com/peterochieng/csp-test
To Reproduce
`import { NextRequest, NextResponse } from 'next/server'
export const nonce = Buffer.from(crypto.randomUUID()).toString('base64')
export function middleware(request: NextRequest) {
const cspHeader =
default-src 'self'; script-src 'self' 'nonce-${nonce}' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' blob: data:; font-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'; upgrade-insecure-requests; connect-src 'self' https://example.com https://ipapi.co/json/;
// Replace newline characters and spaces
const contentSecurityPolicyHeaderValue = cspHeader
.replace(/\s{2,}/g, ' ')
.trim()
const requestHeaders = new Headers(request.headers)
requestHeaders.set('x-nonce', nonce)
requestHeaders.set(
'Content-Security-Policy',
contentSecurityPolicyHeaderValue
)
const response = NextResponse.next({
request: {
headers: requestHeaders,
},
})
response.headers.set(
'Content-Security-Policy',
contentSecurityPolicyHeaderValue
)
return response
}
export const config = {
matcher: [
'/(.*)',
'/', // explicit matcher for root route
],
}
`
2. Run the application on local dev using npm run dev. Test and you'll see it works fine. Open network tab in dev tools and check the response. All scripts, have the nonce added on local dev.
Current vs. Expected behavior
I expect the web app to load well without issues since CSP addition is done by middleware. But, what I get is a blank screen with an error. This error.
Provide environment information
Which area(s) are affected? (Select all that apply)
Middleware
Which stage(s) are affected? (Select all that apply)
Other (Deployed)
Additional context
No response
The text was updated successfully, but these errors were encountered: