Express/Connect middleware for setting Content-Security-Policy HTTP headers according to the W3C CSP specification (v0.3.4). This library provides helper constants (SRC_NONE, SRC_SELF, SRC_DATA) and a convenient getCSP() function to generate middleware for global or route-specific policies. It is minimal and focused solely on CSP headers, unlike more comprehensive security packages such as helmet (which includes CSP as one of many middleware). The package requires Node >= 0.4.0 and has no external dependencies, making it lightweight and easy to integrate into existing Express applications. The API is stable but the package has not seen updates since 2018; consider evaluating its suitability for modern CSP requirements.
npm install content-security-policyVerified import paths — ran on the pinned version, not inferred.
Express app using content-security-policy middleware: global policy from STARTER_OPTIONS, custom policy for a specific route.
Ensure every directive value is a valid source expression string, e.g., 'self' not SRC_SELF directly.
If you need CSP in HTML, consider a different approach or add meta tag manually.
Define your own baseline policy instead of relying on STARTER_OPTIONS.
Use const { getCSP } = require('content-security-policy'); or use dynamic import().Run `npm install content-security-policy --save` and ensure require path is correct.
No dependency data recorded yet.