A Jinja environment does not escape the values put into templates
What it finds
jinja2.Environment(loader=...): Jinja does not escape values put into a template unless told to, so text from users that holds markup ends up in the page as markup (CWE-79). autoescape=True, or select_autoescape(), escapes it.
Reported are environments made without autoescape or with autoescape=False. Calls that pass **kwargs are left alone, and so is a value in a variable.
From the rule's source, template_autoescape_off.rs.
import jinja2from jinja2 import Environment, select_autoescape def environments(loader, options): a = jinja2.Environment(loader=loader)tx0 reports: this Jinja environment does not escape values, since autoescape is not given b = Environment(loader=loader, autoescape=False)tx0 reports: this Jinja environment is told not to escape values c = Environment(loader=loader, autoescape=True) d = Environment(autoescape=select_autoescape()) e = Environment(**options) return a, b, c, d, e Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/python:template-autoescape-off" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
# tx0: ignore[tx0/python:template-autoescape-off] reason="..."tx0 explain tx0/python:template-autoescape-off shows the same in the terminal. Found a false positive? Report it.