[flake8-bandit] Fix misleading docstring for mako-templates (S702)#26432
Merged
Conversation
The "Use instead" example was Template("hello |h"), which demonstrates
nothing: mako's |h filter applies to a variable expression (${ data |h }),
so "hello |h" is just a literal string. It contradicted the rule's own
prose ("to HTML escape the variable data, use ${ data |h }").
- Rework both examples to show the escaping contrast on a variable, with
inline comments matching the convention in sibling rules (e.g.
unsafe_markup_use's `# XSS` / `# Safe`):
bad: Template("${ data }") # Unescaped: vulnerable to XSS.
good: Template("${ data |h }") # HTML-escaped with the `h` filter.
- Drop `n` from the list of "sanitizing" filters in the rationale: mako's
`n` filter disables default filtering, so it cannot sanitize. Keep the
accurate `h` (HTML) and `x` (XML) escaping filters.
nikolauspschuetz
force-pushed
the
docs/s702-mako-example
branch
from
June 27, 2026 18:48
884792c to
fe1758b
Compare
mako-templates (S702)mako-templates (S702)
ntBre
approved these changes
Jul 7, 2026
ntBre
left a comment
Contributor
There was a problem hiding this comment.
Thanks! This does seem like an improvement to me.
mako-templates (S702)flake8-bandit] Fix misleading docstring for mako-templates (S702)
ntBre
enabled auto-merge (squash)
July 7, 2026 15:30
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
mako-templates(S702) rule docstring is misleading in two ways.1. The "Use instead" example demonstrates nothing.
Template("hello |h")escapes nothing: mako's|hfilter applies to avariable expression (
${ data |h }), so"hello |h"is just a literalstring. It also contradicts the rule's own prose just above it:
2. The rationale lists
nas a sanitizing filter.The "Why is this bad?" text said variables should be "sanitized via the
n,horxflags". Mako'snfilter disables default filtering, so itcannot sanitize — listing it alongside the escaping filters is misleading.
Change
Docstring-only; no behavior change.
Rework both examples to show the escaping contrast on a variable, with inline
comments matching the convention in sibling bandit rules (e.g.
unsafe_markup_use's# XSS/# Safe):Drop
nfrom the list of sanitizing filters in the rationale; keep theaccurate
h(HTML) andx(XML) escaping filters.Test plan
cargo dev generate-docsregeneratesdocs/rules/mako-templates.mdcleanly.scripts/check_docs_formatted.pypasses — both snippets are alreadyruff format-clean and parse without error.