本文へスキップ
Skillpedia
セキュリティ75k · #2785

content-security-policy

できること

このスキルは、承認されていないコードやリソースを遮断するブラウザのルールの集まりである、コンテンツセキュリティポリシーを確認し、作成します。クロスサイトスクリプティングに対する追加の防御層が欲しい開発者向けです。

使う場面

  • ✓サイトに、コンテンツセキュリティポリシーのヘッダーがないとき。
  • ✓インラインのスクリプトや安全でない設定が使われているとき。
  • ✓アプリが、利用者が提供したHTMLをページに挿入しているとき。

スキルのリンク

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

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/content-security-policy/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“私のサイトに、未知のスクリプトを遮断するコンテンツセキュリティポリシーを設定し、強制する前にテストしてください。”

毎週5つの新しいスキル。1分で読めます。

仕組み

エージェントは、レポートのみのモードで始まるポリシーを提案し、インラインのスクリプトにはnonceまたはハッシュを使い、安全でない設定を避け、信頼できないHTMLのサニタイズを追加します。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)を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

よくある質問

ポリシーはすぐに強制すべきですか?

いいえ。サイトを壊さずにテストできるよう、レポートのみのモードで始めることを勧めていると、このスキルは説明しています。

コンテンツセキュリティポリシーは、サニタイズの代わりになりますか?

いいえ。攻撃の影響を減らすものの、出力のエンコードとサニタイズの代わりにはならないと、このスキルは説明しています。

Trusted Typesとは何ですか?

HTMLをページに挿入する大きなアプリのための、追加の防御だと、このスキルは説明しています。

詳細

作者による元の説明

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

人気

GitHubのスター
75k
ランキング
#2785
ライセンス
MIT
更新日
2026/10/31

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル