Challenge - 5 Problems
Session Security Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
What does Flask's session cookie 'secure' flag do?
In Flask, setting the 'secure' flag on session cookies means:
Attempts:
2 left
💡 Hint
Think about when cookies are sent over the network.
✗ Incorrect
The 'secure' flag ensures cookies are sent only over HTTPS, protecting them from being sent over unencrypted connections.
❓ component_behavior
intermediate2:00remaining
What happens if Flask's session cookie has 'httponly' set to false?
Consider this Flask configuration:
What is the effect on session security?
app.config['SESSION_COOKIE_HTTPONLY'] = falseWhat is the effect on session security?
Attempts:
2 left
💡 Hint
Think about what 'httponly' controls.
✗ Incorrect
Setting 'httponly' to false allows JavaScript to read the cookie, which can expose it to cross-site scripting (XSS) attacks.
❓ state_output
advanced2:00remaining
What is the output of this Flask session code snippet?
Given the Flask route below, what will be the value of
session.get('count') after three requests?from flask import Flask, session
app = Flask(__name__)
app.secret_key = 'secret'
@app.route('/')
def index():
session['count'] = session.get('count', 0) + 1
return str(session['count'])Attempts:
2 left
💡 Hint
Sessions store data between requests.
✗ Incorrect
The code increments 'count' in the session each time the route is accessed, so it increases by 1 on each request.
📝 Syntax
advanced2:00remaining
Which Flask session configuration line correctly sets the cookie to expire in 1 hour?
Choose the correct way to set Flask session cookie expiration to 3600 seconds.
Attempts:
2 left
💡 Hint
Check the type expected for 'PERMANENT_SESSION_LIFETIME'.
✗ Incorrect
Flask expects a timedelta object for 'PERMANENT_SESSION_LIFETIME', not an integer.
🔧 Debug
expert3:00remaining
Why does this Flask app fail to keep session data between requests?
Examine this Flask app snippet:
After refreshing the page multiple times,
from flask import Flask, session
app = Flask(__name__)
@app.route('/')
def index():
session['user'] = 'Alice'
return 'Set user'After refreshing the page multiple times,
session.get('user') is always null. What is the cause?Attempts:
2 left
💡 Hint
Flask sessions require a secret key to work properly.
✗ Incorrect
Without app.secret_key, Flask cannot sign session cookies, so session data is lost between requests.