Flask - Security Best PracticesYou 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 cookieBSet PERMANENT_SESSION_LIFETIME to 10 minutes and use session.permanent = TrueCManually delete session cookie after 10 minutes in client-side JavaScriptDSet SECRET_KEY to a new value every 10 minutesCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand session lifetime controlPERMANENT_SESSION_LIFETIME controls how long a permanent session lasts.Step 2: Enable permanent sessionsSetting session.permanent = True activates this lifetime for the session cookie.Final Answer:Set PERMANENT_SESSION_LIFETIME to 10 minutes and use session.permanent = True -> Option BQuick Check:Use PERMANENT_SESSION_LIFETIME + session.permanent for expiry [OK]Quick Trick: Use PERMANENT_SESSION_LIFETIME + session.permanent for expiry [OK]Common Mistakes:MISTAKESTrying to delete cookies via JavaScriptConfusing SAMESITE with expiryChanging SECRET_KEY to expire sessions
Master "Security Best Practices" in Flask9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More Flask Quizzes Background Tasks - Task status monitoring - Quiz 10hard Deployment - Database migration in deployment - Quiz 5medium Flask Ecosystem and Patterns - Repository pattern for data access - Quiz 15hard Flask Ecosystem and Patterns - Flask extensions directory - Quiz 7medium Flask Ecosystem and Patterns - Flask extensions directory - Quiz 10hard Middleware and Extensions - Before_request as middleware alternative - Quiz 12easy Security Best Practices - Rate limiting for protection - Quiz 4medium Security Best Practices - SQL injection prevention - Quiz 1easy Testing Flask Applications - Coverage reporting - Quiz 10hard Testing Flask Applications - Why testing matters - Quiz 4medium