Content Security Policy Helpers

June 18, 2025 ยท View on GitHub

Packages for adding a Content Security Policy to your SPA applications:

LibraryVersion
vite-plugin-bun-cspNPM Version
csp-bun-cliNPM Version

Features

  • โœจ Automatically calculates Subresource Integrity (SRI) hashes of JavaScript and CSS assets and adds them to the meta Content Security Policy (CSP) directive in your HTML.
  • ๐Ÿ“š Automatically detects and handles Google Fonts.
  • ๐ŸŽ Fast and lightweight. Packages contain 0 dependencies.

Documentation

Library / Framework Specific Guidance

Emotion CSS

If you are using the Emotion CSS library, which MUI uses by default, then you can add the SHA-256 hash of an empty string 'sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=' to your CSP rather than setting 'unsafe-inline' in your style-src directive.

generateCspPlugin({
  policy: {
    "style-src": ["'self'", "'sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU='"],
  },
}),

Source: https://github.com/emotion-js/emotion/issues/2996#issuecomment-1440609591

License

MIT