Bird
0
0

Given this Django middleware snippet, what will be the Content-Security-Policy header value in the response?

medium📝 component behavior Q4 of 15
Django - Security Best Practices
Given this Django middleware snippet, what will be the Content-Security-Policy header value in the response?
def middleware(get_response):
    def middleware_func(request):
        response = get_response(request)
        response['Content-Security-Policy'] = "script-src 'self' https://cdn.example.com"
        return response
    return middleware_func
ANo Content-Security-Policy header set
B"default-src 'self'"
C"img-src 'self'"
D"script-src 'self' https://cdn.example.com"
Step-by-Step Solution
Solution:
  1. Step 1: Analyze middleware header assignment

    The middleware sets response['Content-Security-Policy'] to "script-src 'self' https://cdn.example.com" explicitly.
  2. Step 2: Confirm header presence in response

    Since the header is set before returning response, it will be present with the assigned value.
  3. Final Answer:

    "script-src 'self' https://cdn.example.com" -> Option D
  4. Quick Check:

    CSP header value = "script-src 'self' https://cdn.example.com" [OK]
Quick Trick: Middleware sets CSP header value directly on response [OK]
Common Mistakes:
MISTAKES
  • Assuming default-src is set instead
  • Thinking header is missing
  • Confusing img-src with script-src directive

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes