Content Security Policy middleware for Express and Node.js. Version 4.0.0 requires Node >=18 and ships TypeScript definitions. It sets the Content-Security-Policy header using a directives object with support for camelCase or kebab-case keys, dynamic values via functions, and a default policy that can be overridden or disabled. Unlike generic CSP libraries, it integrates directly with the Helmet ecosystem and provides sensible defaults to prevent common vulnerabilities like XSS, though it performs minimal validation on the policy itself.
npm install helmet-cspVerified import paths — ran on the pinned version, not inferred.
Configures Express with Content Security Policy middleware using custom directives and dynamic nonce.
Install via npm install helmet-csp and import separately from helmet.
Upgrade Node to version 18 or higher.
Validate your CSP policy with CSP Evaluator or similar before deploying.
Ensure you explicitly define all required directives when disabling defaults, specially defaultSrc.
Use the `report-uri` or `report-to` directives instead, or set the header manually.
Run `npm install helmet-csp` and use `require('helmet-csp')`.Use `const csp = require('helmet-csp');` and call `csp({...})`.Use valid directive names like `defaultSrc` (camelCase) or `default-src` (kebab-case).
No dependency data recorded yet.