-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dcellar-web-ui): add csp rules (#401)
* feat(dcellar-web-ui): add csp * fix(dcellar-web-ui): add unsafe-inline for style * docs(dcellar-web-ui): update changelog
- Loading branch information
Showing
5 changed files
with
78 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
|
||
export function middleware(request: NextRequest) { | ||
const cspHeader = ` | ||
default-src 'self'; | ||
script-src 'self' 'unsafe-eval' https: https://www.googletagmanager.com https://www.google-analytics.com https://analytics.google.com; | ||
script-src-elem 'self' 'unsafe-inline' https: https://www.googletagmanager.com https://www.google-analytics.com https://analytics.google.com; | ||
style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; | ||
img-src 'self' blob: data: https: https://www.google-analytics.com https://www.googletagmanager.com; | ||
font-src 'self' https://fonts.gstatic.com; | ||
connect-src *; | ||
object-src 'none'; | ||
base-uri 'self'; | ||
form-action 'self'; | ||
frame-ancestors 'none'; | ||
frame-src 'self' https://*.walletconnect.com https://verify.walletconnect.com; | ||
media-src 'self'; | ||
manifest-src 'self'; | ||
worker-src 'self' blob:; | ||
upgrade-insecure-requests; | ||
`; | ||
|
||
const cleanCspHeader = cspHeader.replace(/\s+/g, ' ').trim(); | ||
|
||
const requestHeaders = new Headers(request.headers); | ||
requestHeaders.set('Content-Security-Policy', cleanCspHeader); | ||
|
||
const response = NextResponse.next({ | ||
request: { | ||
headers: requestHeaders, | ||
}, | ||
}); | ||
|
||
response.headers.set('Content-Security-Policy', cleanCspHeader); | ||
|
||
return response; | ||
} | ||
|
||
export const config = { | ||
matcher: [ | ||
/* | ||
* Match all request paths except for the ones starting with: | ||
* - api (API routes) | ||
* - _next/static (static files) | ||
* - _next/image (image optimization files) | ||
* - favicon.ico (favicon file) | ||
*/ | ||
{ | ||
source: '/((?!api|_next/static|_next/image|favicon.ico).*)', | ||
missing: [ | ||
{ type: 'header', key: 'next-router-prefetch' }, | ||
{ type: 'header', key: 'purpose', value: 'prefetch' }, | ||
], | ||
}, | ||
], | ||
}; |