Recall & Review
beginner
What is the purpose of using secure cookies in Django sessions?
Secure cookies ensure that session cookies are only sent over HTTPS connections, protecting session data from being intercepted on unsecured networks.
Click to reveal answer
beginner
How does Django's SESSION_COOKIE_HTTPONLY setting improve session security?
Setting SESSION_COOKIE_HTTPONLY to True prevents JavaScript from accessing the session cookie, reducing the risk of cross-site scripting (XSS) attacks stealing session data.
Click to reveal answer
intermediate
Why should session expiration be configured carefully in Django?
Proper session expiration limits the time a session remains valid, reducing the window for attackers to reuse stolen session IDs and improving overall security.
Click to reveal answer
intermediate
What is session fixation and how can Django help prevent it?
Session fixation is an attack where an attacker sets a user's session ID to a known value. Django helps prevent this by rotating the session key after login using the cycle_key() method on the session object.
Click to reveal answer
beginner
Explain the role of CSRF protection in session security within Django.
CSRF protection prevents unauthorized commands from being transmitted from a user that the web application trusts. Django includes built-in CSRF tokens that work with sessions to protect against such attacks.
Click to reveal answer
Which Django setting ensures session cookies are only sent over HTTPS?
✗ Incorrect
SESSION_COOKIE_SECURE makes sure cookies are sent only over HTTPS, protecting session data during transmission.
What does setting SESSION_COOKIE_HTTPONLY to True do?
✗ Incorrect
SESSION_COOKIE_HTTPONLY prevents JavaScript from reading the session cookie, reducing XSS attack risks.
How can Django help prevent session fixation attacks?
✗ Incorrect
Django's cycle_key() method changes the session key after login to prevent attackers from fixing a session ID.
Why is it important to set session expiration in Django?
✗ Incorrect
Setting session expiration limits the time an attacker can reuse a stolen session ID.
What role does CSRF protection play in session security?
✗ Incorrect
CSRF protection uses tokens to ensure requests are from trusted users, protecting sessions from malicious commands.
Describe three key settings or practices in Django that help secure user sessions.
Think about cookie security, session lifetime, and login behavior.
You got /4 concepts.
Explain how session fixation attacks work and how Django defends against them.
Focus on session ID control before and after login.
You got /4 concepts.