0
0
Djangoframework~5 mins

Content Security Policy in Django - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is Content Security Policy (CSP)?
Content Security Policy is a security feature that helps prevent attacks like cross-site scripting (XSS) by controlling which resources (scripts, styles, images) a web page can load.
Click to reveal answer
intermediate
How do you add a Content Security Policy header in Django?
You can add CSP headers in Django by using middleware or third-party packages like django-csp, which lets you define policies in your settings to control resource loading.
Click to reveal answer
beginner
What does the directive script-src 'self' mean in a CSP?
It means the page is only allowed to load and run scripts that come from the same origin (domain) as the page itself, blocking scripts from other sources.
Click to reveal answer
intermediate
Why is it important to avoid using unsafe-inline in CSP?
Using unsafe-inline allows inline scripts, which can open doors to XSS attacks. Avoiding it makes your site safer by only allowing trusted external scripts.
Click to reveal answer
beginner
Name a common Django package used to implement CSP easily.
The package django-csp is commonly used to add and manage Content Security Policy headers in Django projects.
Click to reveal answer
What is the main purpose of Content Security Policy in Django?
ATo control which resources the browser can load to improve security
BTo speed up page loading by caching resources
CTo style the webpage with CSS
DTo manage user authentication
Which directive restricts where scripts can be loaded from in CSP?
Astyle-src
Bimg-src
Cscript-src
Dconnect-src
In Django, which method is commonly used to add CSP headers?
AWriting CSP in templates only
BAdding CSP in models.py
CUsing Django admin panel settings
DUsing middleware or django-csp package
What risk does allowing unsafe-inline scripts in CSP introduce?
ACross-site scripting (XSS) attacks
BSlower page load times
CBroken images
DAuthentication failures
Which of these is NOT a valid CSP directive?
Afont-src
Bdata-src
Cimg-src
Dmedia-src
Explain how Content Security Policy helps protect a Django web application.
Think about what kinds of attacks CSP blocks and how it tells the browser what is safe.
You got /4 concepts.
    Describe how to implement a basic Content Security Policy in a Django project.
    Focus on the steps from installing a package to setting rules.
    You got /4 concepts.