Bird
0
0

Given the following Django settings snippet, what will happen when a user accesses the site over HTTP?

medium📝 component behavior Q13 of 15
Django - Security Best Practices
Given the following Django settings snippet, what will happen when a user accesses the site over HTTP?
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
AThe user will be redirected to the HTTPS version of the site
BThe session cookie will be sent over HTTP
CCSRF protection will be disabled
DThe site will allow HTTP access without redirection
Step-by-Step Solution
Solution:
  1. Step 1: Understand SECURE_SSL_REDIRECT = True

    This setting forces Django to redirect all HTTP requests to HTTPS automatically.
  2. Step 2: Analyze cookie settings

    Both SESSION_COOKIE_SECURE and CSRF_COOKIE_SECURE ensure cookies are only sent over HTTPS, but the redirect happens first.
  3. Final Answer:

    The user will be redirected to the HTTPS version of the site -> Option A
  4. Quick Check:

    SECURE_SSL_REDIRECT = True causes HTTPS redirect [OK]
Quick Trick: HTTPS redirect happens before cookies are sent [OK]
Common Mistakes:
MISTAKES
  • Thinking cookies are sent over HTTP despite redirect
  • Assuming CSRF protection is disabled
  • Believing HTTP access is allowed without redirect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes