Detailed guide for configuring Content Security Policy to properly work with the NowNowNow widget.
Understanding how CSP works and why it matters for widget integration
Content Security Policy (CSP) is a security feature that helps protect websites from various types of attacks, particularly Cross-Site Scripting (XSS). It works by controlling which resources (scripts, styles, images, etc.) can be loaded by the browser.
CSP is implemented via HTTP headers or meta tags that specify which sources are allowed for different types of content. When integrating third-party widgets like NowNowNow, CSP configurations need to be properly set to allow the widget scripts to load and API requests to function.
Identifying and resolving typical problems when using widgets with CSP
The minimum CSP settings needed for the widget to function correctly
Your Content Security Policy must include the following directives for the NowNowNow widget to function correctly:
default-src 'self';
script-src 'self' 'unsafe-inline' https://widget.nownownow.io https://www.nownownow.io;
connect-src 'self' https://www.nownownow.io https://nownownow.io;
style-src 'self' 'unsafe-inline' https://widget.nownownow.io;
img-src 'self' data: https: blob:;
script-src
directive must include widget.nownownow.io to load the widget scriptconnect-src
directive must include the API domain for widget interactions'unsafe-inline'
is required for the widget to apply styling properlySpecific CSP requirements for integrating the NowNowNow widget into your site
When integrating the NowNowNow widget into your website, you'll need to configure your Content Security Policy to allow communication with our domains:
Content-Security-Policy: script-src 'self' https://widget.nownownow.io https://www.nownownow.io;
connect-src 'self' https://www.nownownow.io https://nownownow.io;
style-src 'self' 'unsafe-inline' https://widget.nownownow.io;
img-src 'self' data: https: blob:;
For Next.js applications, add this to your next.config.js
file's headers()
function.
<meta
httpEquiv="Content-Security-Policy"
content="script-src 'self' https://widget.nownownow.io https://www.nownownow.io;
connect-src 'self' https://www.nownownow.io https://nownownow.io;
style-src 'self' 'unsafe-inline' https://widget.nownownow.io;
img-src 'self' data: https: blob:;"
/>
Add this meta tag to your page's head
section. In Next.js App Router, add it to your app/layout.tsx
file.
connect-src
directive must include all NowNowNow domainsscript-src
includes both widget.nownownow.io and www.nownownow.ioBalancing security and functionality in your CSP settings
While it's important to make your CSP compatible with NowNowNow, maintaining security is equally critical:
*.nownownow.io
, use specific subdomains.Pro Tip: Consider using the CSP 'report-uri' directive to collect reports about violations, which can help identify legitimate needs versus actual attacks.
Tools and techniques to identify and fix CSP-related problems
When troubleshooting CSP issues with the NowNowNow widget:
Remember: After making CSP changes, you may need to deploy your updated configuration and clear your browser cache to see the effects.