Recall & Review
beginner
What is XSS and why is it important to prevent it in Flask templates?
XSS (Cross-Site Scripting) is a security issue where attackers inject harmful scripts into web pages viewed by others. Preventing XSS in Flask templates keeps users safe by stopping malicious code from running in their browsers.
Click to reveal answer
beginner
How does Flask's Jinja2 template engine help prevent XSS by default?
Jinja2 automatically escapes special characters like <, >, &, and " in variables, turning them into safe HTML entities. This stops harmful scripts from running when user data is shown in templates.
Click to reveal answer
intermediate
What does the Jinja2 filter |safe do, and why should it be used carefully?
The |safe filter tells Jinja2 not to escape the content, rendering it as raw HTML. Use it only when you are sure the content is safe, because it can open the door to XSS if used with untrusted data.
Click to reveal answer
beginner
How can you safely include user input in Flask templates?
Simply pass user input as variables to the template without marking them safe. Jinja2 will escape them automatically, preventing scripts from running.
Click to reveal answer
intermediate
What is a common mistake that can lead to XSS vulnerabilities in Flask templates?
A common mistake is using the |safe filter or disabling autoescaping on untrusted user input. This allows malicious scripts to run and can harm users.
Click to reveal answer
What does Jinja2 do by default to prevent XSS when rendering variables?
✗ Incorrect
Jinja2 automatically escapes special characters like < and > to prevent scripts from running.
Which Jinja2 filter disables escaping and should be used with caution?
✗ Incorrect
The |safe filter disables escaping and renders content as raw HTML.
If you want to display user input safely in a Flask template, what should you do?
✗ Incorrect
Passing user input normally lets Jinja2 escape it automatically, preventing XSS.
What risk does using the |safe filter on untrusted user input create?
✗ Incorrect
Using |safe on untrusted input can allow malicious scripts to run, causing XSS.
Which of these is NOT a way to prevent XSS in Flask templates?
✗ Incorrect
Disabling autoescaping globally removes protection and can cause XSS.
Explain how Flask and Jinja2 work together to prevent XSS attacks in templates.
Think about what happens when you put user data inside {{ }} in a template.
You got /4 concepts.
Describe a common mistake that can cause XSS vulnerabilities in Flask templates and how to avoid it.
Focus on filters and escaping settings.
You got /4 concepts.