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
In work projects I always use setups for the follwing services:
DatoCMS for Content Management
Vercel for Deployment
Sentry for Monitoring
Stripe for Payment
Algolia for Search
So basically I copy&paste the CSP directives required for those to work from project to project. To avoid that I thought it could be good idea if the lib shipped reusable and stackable presets for common services
Rough design
// presets.tsimporttype{NextRequest}from'next/server'importtype{CspDirectives}from'./types'import{isPreviewModeRequest}from'./matchers'// different preset directives based on request data and dev modetypePresetCfg={req: NextRequestisDev: boolean}typePreset=(cfg: PresetCfg)=>CspDirectivesconstdefault: Preset=()=>{return{"default-src": ['self'],"object-src" : ['none'],"base-uri": ['none'],}}constnextjs: Preset=({ isDev })=>{return{"script-src": isDev ? ['self','unsafe-inline','unsafe-eval'] : []"style-src": isDev ? ['self','unsafe-inline'] : []}}constdatocms: Preset=({ req, isDev })=>{return{"connect-src": isDev||isPreviewModeRequest(req) ? ['https://api.datocms.com'] : []"img-src": ['https://datocms-assets.com']}}constpresets={
default,
nextjs,
datocms,}typeCspPresets=keyoftypeofpresets
// middleware.jsimport{chainMatch,isPageRequest,csp,strictDynamic}from'@next-safe/middleware';constsecurityMiddleware=[csp({// stackable presetspresets: ['default','nextjs','datocms'],// custom directives on top of presetsdirectives: {'img-src': ['self','data:','https://images.unsplash.com'],'font-src': ['self','https://fonts.gstatic.com'],},}),strictDynamic(),];exportdefaultchainMatch(isPageRequest)(...securityMiddleware);})
The text was updated successfully, but these errors were encountered:
Moitivation
In work projects I always use setups for the follwing services:
So basically I copy&paste the CSP directives required for those to work from project to project. To avoid that I thought it could be good idea if the lib shipped reusable and stackable presets for common services
Rough design
The text was updated successfully, but these errors were encountered: