Bird
0
0

You want to implement a Flask app that invalidates the session cookie after 10 minutes of inactivity. Which approach is best?

hard📝 Application Q9 of 15
Flask - Security Best Practices
You want to implement a Flask app that invalidates the session cookie after 10 minutes of inactivity. Which approach is best?
ASet SESSION_COOKIE_SAMESITE to 'Strict' to expire cookie
BSet PERMANENT_SESSION_LIFETIME to 10 minutes and use session.permanent = True
CManually delete session cookie after 10 minutes in client-side JavaScript
DSet SECRET_KEY to a new value every 10 minutes
Step-by-Step Solution
Solution:
  1. Step 1: Understand session lifetime control

    PERMANENT_SESSION_LIFETIME controls how long a permanent session lasts.
  2. Step 2: Enable permanent sessions

    Setting session.permanent = True activates this lifetime for the session cookie.
  3. Final Answer:

    Set PERMANENT_SESSION_LIFETIME to 10 minutes and use session.permanent = True -> Option B
  4. Quick Check:

    Use PERMANENT_SESSION_LIFETIME + session.permanent for expiry [OK]
Quick Trick: Use PERMANENT_SESSION_LIFETIME + session.permanent for expiry [OK]
Common Mistakes:
MISTAKES
  • Trying to delete cookies via JavaScript
  • Confusing SAMESITE with expiry
  • Changing SECRET_KEY to expire sessions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes