To reduce the risk of cross-site scripting attacks, templating systems, such as Twig, Django, Smarty,
Groovy's template engine, allow configuration of automatic variable escaping before rendering templates. When escape occurs, characters
that make sense to the browser (eg: <a>) will be transformed/replaced with escaped/sanitized values (eg: & lt;a& gt; ).
Auto-escaping is not a magic feature to annihilate all cross-site scripting attacks, it depends on the strategy applied and the context, for example a "_html auto-escaping_" strategy
(which only transforms html characters into html entities) will not be relevant
when variables are used in a html attribute because ':' character is not
escaped and thus an attack as below is possible:
<a href="{{ myLink }}">link</a> // myLink = javascript:alert(document.cookie)
<a href="javascript:alert(document.cookie)">link</a> // JS injection (XSS attack)
There is a risk if you answered yes to any of those questions.
from jinja2 import Environment env = Environment() # Sensitive: New Jinja2 Environment has autoescape set to false env = Environment(autoescape=False) # Sensitive:
from jinja2 import Environment env = Environment(autoescape=True) # Compliant