mark_safe is given a string built by formatting, so the values put into it are not escaped

tx0/python:mark-safe-formattedrecommendedwarningsecurity, cwe-79

What it finds

mark_safe tells Django that a string is finished HTML and must not be escaped. When the string is built with an f-string, %, format or +, the values put into it, which may come from users, end up in the page unescaped. format_html escapes the values and marks the result safe.

From the rule's source, mark_safe_formatted.rs.

Example from the rule's tests
from django.utils.safestring import mark_safe  def link(url, name):    a = mark_safe(f"<a href='{url}'>{name}</a>")tx0 reports: this string is built by formatting    b = mark_safe("<b>%s</b>" % name)tx0 reports: this string is built by formatting    c = mark_safe("<br>")    return a, b, c
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

tx0.toml
[rules]
"tx0/python:mark-safe-formatted" = "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:mark-safe-formatted] reason="..."

tx0 explain tx0/python:mark-safe-formatted shows the same in the terminal. Found a false positive? Report it.