Skillpedia
الأمان75k · #2785

content-security-policy

ما الذي تفعله

تتحقق هذه المهارة من سياسة أمن المحتوى وتبنيها، وهي مجموعة قواعد للمتصفح تمنع الكود والموارد غير المعتمدة. وهي موجهة إلى المطورين الذين يريدون طبقة حماية إضافية ضد هجمات cross-site scripting.

متى تستخدمها

  • ✓عندما لا يملك موقعك ترويسة سياسة أمن محتوى.
  • ✓عندما تُستخدم سكربتات مضمّنة أو إعدادات غير آمنة.
  • ✓عندما يُدرج تطبيقك HTML يقدمه المستخدم في الصفحة.

رابط المهارة

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

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/content-security-policy/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“اضبط سياسة أمن محتوى لموقعي تمنع السكربتات المجهولة، واختبرها قبل فرضها.”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

يقترح الوكيل سياسة تبدأ في وضع التقرير فقط، وتستخدم nonce أو hash للسكربتات المضمّنة، وتتجنب الإعدادات غير الآمنة، وتضيف تنقية للـ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
آخر تحديث
31‏/10‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة