Menu

Content Security Policy for Sites That Embed Third-Party Widgets
πŸ“°

Content Security Policy for Sites That Embed Third-Party Widgets

DEV Community: securityΒ·desgh whiteΒ·about 3 hours ago
#APELPgZJ
#devtosecurity#devto#dev#inline#report
Reading 0:00
15s threshold

A strict Content Security Policy breaks most third-party widgets on first deploy. Chat widgets, analytics, A/B testing scripts β€” they all inject inline styles, eval code, or load from domains you haven't whitelisted. The fix is not to disable CSP; it is to build it incrementally.

Start in report-only mode

Content-Security-Policy-Report-Only: default-src 'self'; report-uri /csp-reports

Enter fullscreen mode

Exit fullscreen mode

Deploy this header and collect violation reports for a week. The reports tell you exactly which domains and inline patterns your page actually uses.

Build the allowlist from reports

# Parse CSP reports to extract unique violated directives and sources violations = defaultdict ( set ) for report in reports : d = report [ 'csp-report' ] violations [ d [ 'violated-directive' ] ] . add ( d [ 'blocked-uri' ] )

Enter fullscreen mode

Exit fullscreen mode

The output is your allowlist.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.