Skip to content

Commit cc73078

Browse files
committed
fix: enable Jinja2 autoescape to resolve Bandit B701 (CWE-94)
Use select_autoescape() in the build command's Jinja2 Environment to satisfy the jinja2_autoescape_false security check. This enables HTML escaping only for .html/.htm/.xml extensions, leaving YAML and .env templates functionally unchanged.
1 parent b62d3a7 commit cc73078

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/qr_sampler/cli/build_cmd.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def _render_template(template_name: str, context: dict[str, Any]) -> str:
8181
Rendered string.
8282
"""
8383
try:
84-
from jinja2 import Environment, FileSystemLoader
84+
from jinja2 import Environment, FileSystemLoader, select_autoescape
8585
except ImportError as exc:
8686
raise click.ClickException(
8787
"The 'build' command requires Jinja2. Install with: pip install qr-sampler[cli]"
@@ -90,6 +90,7 @@ def _render_template(template_name: str, context: dict[str, Any]) -> str:
9090
templates_dir = _resolve_templates_dir()
9191
env = Environment(
9292
loader=FileSystemLoader(str(templates_dir)),
93+
autoescape=select_autoescape(),
9394
keep_trailing_newline=True,
9495
trim_blocks=True,
9596
lstrip_blocks=True,

0 commit comments

Comments
 (0)