Bird
0
0

You added this CSP header in Django but your inline scripts stopped working:

medium📝 Debug Q14 of 15
Django - Security Best Practices
You added this CSP header in Django but your inline scripts stopped working:
response['Content-Security-Policy'] = "default-src 'self'"
What is the likely cause and fix?
AInline scripts blocked; add 'unsafe-inline' to script-src directive
BHeader syntax error; remove quotes around 'self'
CMissing HTTPS; change 'self' to https://self
DNo fix needed; inline scripts should work by default
Step-by-Step Solution
Solution:
  1. Step 1: Understand CSP default-src effect on scripts

    default-src 'self' blocks inline scripts by default because inline scripts are unsafe.
  2. Step 2: Fix by allowing inline scripts explicitly

    Adding 'unsafe-inline' to script-src directive allows inline scripts to run.
  3. Final Answer:

    Inline scripts blocked; add 'unsafe-inline' to script-src directive -> Option A
  4. Quick Check:

    Inline scripts need 'unsafe-inline' in CSP [OK]
Quick Trick: Add 'unsafe-inline' to allow inline scripts in CSP [OK]
Common Mistakes:
MISTAKES
  • Removing quotes around 'self' breaks CSP syntax
  • Changing 'self' to https://self is invalid
  • Assuming inline scripts work without explicit permission

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes