Skip to content
Skillpedia
Security75k · #2785

content-security-policy

What it does

This skill checks and builds a content security policy, a set of browser rules that block unapproved code and resources. It is for developers who want an extra layer of protection against cross-site scripting.

When to use it

  • ✓When your site has no content security policy header.
  • ✓When inline scripts or unsafe settings are in use.
  • ✓When your app inserts user-provided HTML into the page.

Skill link

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/content-security-policy/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/content-security-policy/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute →

Example of what to ask your AI

“Set up a content security policy for my site that blocks unknown scripts, and test it before enforcing it.”

5 new skills a week. 1 minute to read.

How it works

The agent proposes a policy that starts in report-only mode, uses nonces or hashes for inline scripts, avoids unsafe settings, and adds sanitizing for untrusted HTML.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Implement a content security policy

Content Security Policy prevents cross-site scripting (XSS), clickjacking, and data injection attacks by controlling which resources can be loaded and executed on your pages. It reduces blast radius, but it does not replace output encoding and sanitization.

Quick Reference

  • Start with Content-Security-Policy-Report-Only to test without breaking your site
  • Use nonces or hashes for inline scripts instead of unsafe-inline
  • Avoid unsafe-eval unless absolutely necessary
  • Set strict default-src then allow specific sources
  • Monitor CSP reports to catch violations
  • Sanitize untrusted HTML before rendering it into the DOM
  • Use Trusted Types in larger apps as defense in depth for DOM XSS sinks

Check

Check if this website implements a Content Security Policy header and analyze its directives. Also review any use of innerHTML, dangerouslySetInnerHTML, HTML template injection, and Trusted Types enforcement for large applications.

Fix

Implement a strict Content Security Policy to prevent XSS attacks and control resource loading. Sanitize untrusted HTML before rendering and add Trusted Types enforcement where the application has enough DOM injection surface to benefit from it.

Explain

Explain how CSP provides a security layer that helps detect and mitigate XSS and data injection attacks, and why sanitization is still required before rendering untrusted HTML.

Code Review

Review server config, headers, forms, and integration points related to Implement a content security policy. Flag exact responses, cookies, or browser behaviors that violate the rule, and verify them against the effective production-like response. Inspect HTML injection sinks and note whether Trusted Types or sanitization protects them.


For full implementation details, code examples, and framework-specific guidance, see references/rule.md.

Rule page: https://frontendchecklist.io/rules/security/content-security-policy

FAQ

Should I enforce the policy right away?

No. The skill recommends starting in report-only mode to test without breaking the site.

Does a content security policy replace sanitizing?

No. The skill says it reduces the impact of attacks but does not replace output encoding and sanitization.

What is Trusted Types?

The skill describes it as an added defense for larger apps that insert HTML into the page.

Details

Original description by the author

Use when reviewing headers, forms, cookies, or third-party integrations related to Implement a content security policy. Validate the effective browser and HTTP behavior in a production-like environment.

repo: thedaviddias/Front-End-Checklist

Popularity

GitHub stars
75k
Ranking position
#2785
License
MIT
Updated
10/31/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills