A. Empty secret_key means sessions are not securely signed
B. Missing import of session from flask
C. Route decorator syntax is incorrect
D. Session variable name 'logged_in' is invalid
Solution
Step 1: Check secret_key value
The secret_key is set to an empty string, which is insecure and disables proper signing of session cookies.
Step 2: Validate other code parts
Imports and route syntax are correct; session variable names can be any string.
Final Answer:
Empty secret_key means sessions are not securely signed -> Option A
Quick Check:
Empty secret_key disables secure session signing = C [OK]
Hint: Never use empty string as secret_key for session security [OK]
Common Mistakes:
Ignoring empty secret_key security risk
Thinking session variable names must follow strict rules
Assuming route decorator syntax is wrong here
5. You want to improve session security in your Flask app by ensuring cookies are only sent over HTTPS and not accessible by JavaScript. Which configuration should you add?
hard
A. app.config.update({'SESSION_COOKIE_SECURE': true, 'SESSION_COOKIE_HTTPONLY': true})
B. app.config.update({'SESSION_COOKIE_SECURE': false, 'SESSION_COOKIE_HTTPONLY': false})
C. app.config.update({'SESSION_COOKIE_SAMESITE': 'null'})
D. app.config.update({'SESSION_COOKIE_DOMAIN': 'localhost'})
Solution
Step 1: Understand cookie security flags
SESSION_COOKIE_SECURE=true ensures cookies are sent only over HTTPS, and SESSION_COOKIE_HTTPONLY=true prevents JavaScript access.
Step 2: Evaluate other options
A sets domain but not security flags, B disables security flags, C changes SameSite but not HTTPS or HttpOnly.
Final Answer:
app.config.update({'SESSION_COOKIE_SECURE': true, 'SESSION_COOKIE_HTTPONLY': true}) -> Option A
Quick Check:
Secure and HttpOnly cookies = D [OK]
Hint: Set SESSION_COOKIE_SECURE and SESSION_COOKIE_HTTPONLY to true [OK]
Common Mistakes:
Setting SESSION_COOKIE_SECURE to false
Confusing SameSite with Secure and HttpOnly flags
Not setting HttpOnly to prevent JavaScript access
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.