Bird
0
0

In a Django template, if you apply the safe filter to {{ user_input|safe }} where user_input contains malicious JavaScript, what is the consequence?

medium📝 Debug Q6 of 15
Django - Security Best Practices
In a Django template, if you apply the safe filter to {{ user_input|safe }} where user_input contains malicious JavaScript, what is the consequence?
ADjango will sanitize the script automatically.
BThe malicious script will be rendered and executed in the browser.
CThe script will be escaped and shown as text.
DThe template will raise a rendering error.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the 'safe' filter effect

    The 'safe' filter tells Django not to escape the variable, rendering it as raw HTML.
  2. Step 2: Recognize security implications

    If the input contains malicious JavaScript, it will be executed by the browser, causing an XSS vulnerability.
  3. Final Answer:

    The malicious script will be rendered and executed in the browser. -> Option B
  4. Quick Check:

    'safe' disables escaping, enabling script execution [OK]
Quick Trick: 'safe' disables escaping; use cautiously [OK]
Common Mistakes:
MISTAKES
  • Assuming Django sanitizes input with 'safe'
  • Believing scripts are always escaped
  • Thinking template errors occur on unsafe input

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes