Bird
0
0

Identify the error in this Flask code snippet for input sanitization:

medium📝 Debug Q14 of 15
Flask - Security Best Practices
Identify the error in this Flask code snippet for input sanitization:
from flask import escape
user_input = request.args.get('name')
safe_input = escape(user_input)
return safe_input
Aescape() should not be used on user input
Brequest.args.get() returns None if 'name' missing, causing error in escape()
CMissing import of request from flask
Dsafe_input should be converted to int before returning
Step-by-Step Solution
Solution:
  1. Step 1: Check the imports

    The code imports escape from Flask but uses request without importing it.
  2. Step 2: Identify the resulting error

    This causes a NameError because request is undefined.
  3. Final Answer:

    Missing import of request from flask -> Option C
  4. Quick Check:

    Missing from flask import request [OK]
Quick Trick: Import request from flask before using it [OK]
Common Mistakes:
MISTAKES
  • Thinking None causes TypeError in escape()
  • Believing escape() should not be used on user input
  • Assuming input needs int conversion

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes