Bird
0
0

You see this Flask template code:

medium📝 Debug Q14 of 15
Flask - Security Best Practices
You see this Flask template code:
<p>Message: {{ message|safe }}</p>

What is the main problem with this code if message contains user input?
AIt will cause a syntax error in the template.
BIt disables escaping, allowing XSS attacks if input is malicious.
CIt will remove all HTML tags from the message.
DIt automatically sanitizes the input, so no problem.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the effect of |safe filter

    The |safe filter tells Flask not to escape the content, rendering raw HTML.
  2. Step 2: Recognize security risk with user input

    If message is user input, malicious scripts can run, causing XSS attacks.
  3. Final Answer:

    It disables escaping, allowing XSS attacks if input is malicious. -> Option B
  4. Quick Check:

    Using |safe on user input = security risk [OK]
Quick Trick: Avoid |safe on user input to prevent XSS [OK]
Common Mistakes:
MISTAKES
  • Thinking |safe sanitizes input
  • Believing it causes syntax errors
  • Assuming it strips HTML tags

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes