Challenge - 5 Problems
XSS Prevention Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What will this Django template output?
Consider this Django template snippet:
If
{% autoescape on %}{{ user_input }}{% endautoescape %}If
user_input is <script>alert('XSS')</script>, what will be rendered in the browser?Django
{% autoescape on %}{{ user_input }}{% endautoescape %}Attempts:
2 left
💡 Hint
Think about what autoescape does to HTML special characters.
✗ Incorrect
With autoescape on, Django converts special characters like < and > into HTML entities, preventing the script from running.
📝 Syntax
intermediate2:00remaining
Which template syntax disables autoescaping for a variable?
In Django templates, how do you output a variable
user_input without escaping HTML?Attempts:
2 left
💡 Hint
One option is a filter that marks the string as safe.
✗ Incorrect
The |safe filter tells Django not to escape the variable, rendering HTML as is.
🔧 Debug
advanced2:00remaining
Why does this template still allow XSS?
Given this template:
and
{{ user_input|safe }}and
user_input contains <img src=x onerror=alert(1)>, why is this a security risk?Django
{{ user_input|safe }}Attempts:
2 left
💡 Hint
Think about what |safe does to user input.
✗ Incorrect
Using |safe disables escaping, so malicious HTML or scripts in user input run in the browser.
🧠 Conceptual
advanced2:00remaining
How does Django's autoescaping protect against XSS?
Which statement best describes Django's autoescaping feature in templates?
Attempts:
2 left
💡 Hint
Think about what happens to < and > characters.
✗ Incorrect
Autoescaping replaces <, >, &, and quotes with HTML entities so browsers show them as text, not code.
❓ state_output
expert2:00remaining
What is the output count of links rendered safely?
In this Django template:
Given
{% for link in links %}{{ link|urlize }}
{% endfor %}Given
links = ['http://example.com', 'javascript:alert(1)', 'https://safe.com'], how many links will be rendered as clickable safe URLs?Django
{% for link in links %}{{ link|urlize }}<br>{% endfor %}Attempts:
2 left
💡 Hint
urlize only makes safe URLs clickable, ignoring javascript: links.
✗ Incorrect
urlize converts http and https URLs to links but ignores javascript: URLs for safety.