SESSION_COOKIE_SECURE = True do to improve session security?Setting SESSION_COOKIE_SECURE = True tells the browser to send the session cookie only over HTTPS, preventing it from being sent over unencrypted connections where it could be intercepted.
SESSION_EXPIRE_AT_BROWSER_CLOSE = True. What is the effect on user sessions?When SESSION_EXPIRE_AT_BROWSER_CLOSE is True, Django sets the session cookie without an expiration date, so it is deleted when the browser closes, ending the session.
def process_request(self, request):
request.session['user_role'] = 'admin'
What security risk does this code introduce?def process_request(self, request): request.session['user_role'] = 'admin'
This code sets the user role to 'admin' on every request, ignoring the real user's permissions. This can allow unauthorized access and privilege escalation.
Setting SESSION_COOKIE_HTTPONLY = True prevents JavaScript from accessing the session cookie, reducing risk of theft via cross-site scripting.
SESSION_COOKIE_SECURE = True SESSION_COOKIE_HTTPONLY = True SESSION_EXPIRE_AT_BROWSER_CLOSE = TrueWhat is the combined effect on the session cookie?
These settings together ensure the session cookie is secure: sent only via HTTPS (SESSION_COOKIE_SECURE), not accessible by JavaScript (SESSION_COOKIE_HTTPONLY), and removed when the browser closes (SESSION_EXPIRE_AT_BROWSER_CLOSE).