0
0
Flaskframework~20 mins

Why security is critical in Flask - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Flask Security Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why is input validation important in Flask apps?

In Flask, why should you always validate user input before processing it?

ATo reduce the size of the app's code
BTo make the app run faster by skipping checks
CTo allow users to enter any data without restrictions
DTo prevent attackers from sending harmful data that can break the app or steal data
Attempts:
2 left
💡 Hint

Think about what happens if bad data reaches your app unchecked.

component_behavior
intermediate
2:00remaining
What happens if you don't use CSRF protection in Flask forms?

Consider a Flask app with forms but no CSRF protection. What risk does this create?

AUsers will see error messages on every form submission
BThe app will crash when users submit forms
CAttackers can trick users into submitting unwanted actions without their knowledge
DForms will not send any data to the server
Attempts:
2 left
💡 Hint

Think about what CSRF stands for and what it protects against.

🔧 Debug
advanced
3:00remaining
Identify the security flaw in this Flask route code

What security issue does this Flask route have?

Flask
from flask import Flask, request
app = Flask(__name__)

@app.route('/delete', methods=['POST'])
def delete_item():
    item_id = request.form['id']
    # Deletes item without checking user permissions
    delete_from_db(item_id)
    return 'Deleted'
AIt deletes items without verifying if the user is allowed to delete them
BIt returns a string instead of JSON
CIt does not check if item_id is an integer
DIt uses POST method which is insecure
Attempts:
2 left
💡 Hint

Think about what could happen if anyone can call this route.

📝 Syntax
advanced
2:00remaining
Which Flask code snippet correctly sets a secure cookie?

Choose the code that sets a cookie with security best practices in Flask.

Aresponse.set_cookie('session', 'abc123', httponly=False, secure=False)
Bresponse.set_cookie('session', 'abc123', httponly=True, secure=True, samesite='Lax')
Cresponse.set_cookie('session', 'abc123')
Dresponse.set_cookie('session', 'abc123', expires='never')
Attempts:
2 left
💡 Hint

Think about cookie flags that protect against theft and cross-site attacks.

state_output
expert
3:00remaining
What is the output after running this Flask session code?

Given this Flask code snippet, what will be the value of session['count'] after two requests?

Flask
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'])

# Assume two requests are made by the same client in order.
A"2"
B"1"
CKeyError because 'count' is missing
D"0"
Attempts:
2 left
💡 Hint

Remember Flask sessions keep data between requests for the same client.