# csp-middleware Content Security Policy middleware for Remix. It generates a request nonce for handlers and renderers and adds the configured policy to HTML responses. ## Features - Static policies or a per-request policy factory - Enforced and report-only policies side by side, sharing one nonce - Named reporting endpoints for policy violation reports - HTML-only default with custom response filtering - Cryptographically random nonces shared with internal frame renders - Existing policies preserved as separate policies ## Installation ```sh npm i remix ``` ## Usage ```tsx import { createRouter } from 'remix/router' import { csp, getCspNonce } from 'remix/middleware/csp' import { render } from 'remix/middleware/render' import { Frame } from 'remix/component' let router = createRouter({ middleware: [ csp({ policy({ nonce }) { return { defaultSrc: ["'self'"], scriptSrc: [`'nonce-${nonce}'`], styleSrc: [`'nonce-${nonce}'`], objectSrc: ["'none'"], baseUri: ["'self'"], } }, }), render(), ], }) router.get('/', (context) => context.render(