Bird
0
0

What happens if you use the 'safe' filter on untrusted user input in a Django template?

medium📝 component behavior Q5 of 15
Django - Security Best Practices
What happens if you use the 'safe' filter on untrusted user input in a Django template?
AThe input is rendered as raw HTML, risking XSS attacks.
BDjango automatically sanitizes the input before rendering.
CThe input is escaped twice, making it safe.
DAn error is raised to prevent unsafe rendering.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the 'safe' filter effect

    The 'safe' filter disables escaping and renders the content as raw HTML.
  2. Step 2: Recognize the risk with untrusted input

    If the input is untrusted, this allows malicious scripts to run, causing XSS vulnerabilities.
  3. Final Answer:

    Using 'safe' on untrusted input renders raw HTML and risks XSS. -> Option A
  4. Quick Check:

    'safe' on untrusted input = B [OK]
Quick Trick: Never use 'safe' on untrusted input to avoid XSS [OK]
Common Mistakes:
MISTAKES
  • Assuming Django sanitizes automatically with 'safe'
  • Thinking 'safe' escapes input twice
  • Expecting an error to prevent unsafe rendering

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes