The `content-security-policy-builder` package, currently at version 2.3.0, provides a focused utility for programmatically constructing Content Security Policy (CSP) strings from a JavaScript object or Map. It streamlines the process of defining CSP directives by supporting various input formats, including `camelCased` or `dash-separated` directive names, and accepting both strings and arrays for directive values. The module is explicitly designated as feature-complete, with the maintainer indicating that future development will be limited to maintenance. This means no new features or breaking changes are planned, making it a stable, though static, choice for generating CSP headers. Its key differentiator lies in its robust input parsing and its singular, complete focus on translating structured input into a valid CSP string.
npm install content-security-policy-builderVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use the `content-security-policy-builder` to construct CSP strings from both a plain JavaScript object and a Map, showcasing its flexibility with different directive naming conventions and value types.
Upgrade your Node.js environment to version 18.0.0 or newer.
Regularly review your generated CSP against the latest W3C Content Security Policy specification to ensure it remains effective and secure, manually updating directives as needed.
Thoroughly test and review your generated CSP using browser developer tools and online CSP validators (e.g., CSP Evaluator) to ensure its correctness and effectiveness.
Change your import statement from `const builder = require('content-security-policy-builder');` to `import builder from 'content-security-policy-builder';`.Change your import statement to `import builder from 'content-security-policy-builder';`.
No dependency data recorded yet.