Bird
0
0

You want to secure your Django site so that session and CSRF cookies are only sent over HTTPS, and all HTTP requests redirect to HTTPS. Which combination of settings achieves this securely?

hard📝 Application Q15 of 15
Django - Security Best Practices
You want to secure your Django site so that session and CSRF cookies are only sent over HTTPS, and all HTTP requests redirect to HTTPS. Which combination of settings achieves this securely?
ASECURE_SSL_REDIRECT = True, SESSION_COOKIE_SECURE = True, CSRF_COOKIE_SECURE = True
BSECURE_SSL_REDIRECT = False, SESSION_COOKIE_SECURE = True, CSRF_COOKIE_SECURE = True
CSECURE_SSL_REDIRECT = True, SESSION_COOKIE_SECURE = False, CSRF_COOKIE_SECURE = False
DSECURE_SSL_REDIRECT = False, SESSION_COOKIE_SECURE = False, CSRF_COOKIE_SECURE = False
Step-by-Step Solution
Solution:
  1. Step 1: Ensure HTTP requests redirect to HTTPS

    Setting SECURE_SSL_REDIRECT = True forces all HTTP requests to HTTPS, preventing insecure access.
  2. Step 2: Secure cookies for session and CSRF

    Setting both SESSION_COOKIE_SECURE and CSRF_COOKIE_SECURE to True ensures cookies are only sent over HTTPS connections.
  3. Step 3: Evaluate other options

    The other options fail to secure either redirection or cookies properly, leaving security gaps.
  4. Final Answer:

    SECURE_SSL_REDIRECT = True, SESSION_COOKIE_SECURE = True, CSRF_COOKIE_SECURE = True -> Option A
  5. Quick Check:

    All three settings True secures HTTPS and cookies [OK]
Quick Trick: Enable all three: redirect and secure cookies [OK]
Common Mistakes:
MISTAKES
  • Not enabling HTTPS redirect
  • Leaving cookie secure flags False
  • Assuming one setting is enough alone

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes