Challenge - 5 Problems
Django Security Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Why is CSRF protection important in Django?
Django includes built-in CSRF protection. What is the main reason this security feature is important?
Attempts:
2 left
💡 Hint
Think about what happens if a user unknowingly sends a harmful request.
✗ Incorrect
CSRF protection stops attackers from making users perform actions they did not intend, like changing passwords or making purchases.
❓ component_behavior
intermediate2:00remaining
What happens if DEBUG=True in production?
In Django settings, what is the risk of leaving
DEBUG=True when your site is live?Attempts:
2 left
💡 Hint
Consider what information error pages might reveal.
✗ Incorrect
When DEBUG=True, error pages show detailed info like file paths and settings, which attackers can use to find weaknesses.
📝 Syntax
advanced2:00remaining
Which middleware enables Django's security features?
Select the correct middleware line to add in
MIDDLEWARE for security headers.Attempts:
2 left
💡 Hint
This middleware adds headers like HSTS and others for security.
✗ Incorrect
SecurityMiddleware adds important security headers and helps enforce HTTPS.
🔧 Debug
advanced2:00remaining
What error occurs if SECRET_KEY is missing?
If you remove or leave empty the
SECRET_KEY in Django settings, what error will you see when running the server?Attempts:
2 left
💡 Hint
SECRET_KEY is required for cryptographic signing.
✗ Incorrect
Django raises ImproperlyConfigured if SECRET_KEY is missing or empty because it is essential for security.
❓ state_output
expert3:00remaining
What is the output of this Django view with improper user input handling?
Consider this Django view code snippet:
from django.http import HttpResponse
def greet(request):
name = request.GET.get('name', 'Guest')
return HttpResponse(f"Hello, {name}!")
What security risk does this code have and what will be the output if a user visits /greet?name=<script>alert('XSS')</script>?Django
from django.http import HttpResponse def greet(request): name = request.GET.get('name', 'Guest') return HttpResponse(f"Hello, {name}!")
Attempts:
2 left
💡 Hint
Think about how raw user input is handled in HttpResponse.
✗ Incorrect
This code directly inserts user input into the response without escaping, allowing malicious scripts to run in the browser.