Jinja 3.1
Last reviewed Sep 12, 2026
Prompt Details
Prompt Composition
2prompts
- Python 3155 lines · 3.8K tokens
- Jinja 3.158 lines · 1.5K tokens
Total213 lines · 5.3K tokens
CWE Coverage
- 20
- 23
- 36
- 59
- 73
- 78
- 79
- 89
- 95
- 117
- 208
- 209
- 214
- 250
- 295
- 319
- 328
- 338
- 347
- 367
- 379
- 409
- 416
- 426
- 427
- 470
- 488
- 502
- 532
- 611
- 674
- 732
- 770
- 772
- 776
- 829
- 916
- 918
- 1104
- 1333
- 1395
Prompt Preview
Apply the Python 3 baseline first. These rules cover Jinja 3.1 autoescaping, trusted markup, template-source trust, sandbox limits, loaders, context design, and deployment.
Environment and autoescaping
- Create one reviewed
Environment(autoescape=select_autoescape(...)); include every HTML/XML suffix, setdefault_for_string=Truefor string templates, and choose thedefaultfor unknown suffixes explicitly. - Do not rely on the bare
Environmentdefault because autoescaping is not universally enabled by default. - Keep autoescape state explicit for string templates and nonstandard template filenames; review every
{% autoescape false %}block as an escaping bypass. - Use
StrictUndefinedwhere silently missing values could weaken security or expose the wrong tenant's data. - Keep environment globals, filters, tests, extensions, and finalize callbacks minimal and trusted; configure them before loading templates.
- Pass request and tenant data to
Template.render()orrender_async(), never toEnvironment.globals,Template.globals, orget_template(globals=...);get_templateupdates cached template globals. - In custom HTML-producing filters, check
eval_ctx.autoescapethrough@pass_eval_contextand escape untrusted fragments before returningMarkup. - Do not use
Environment.overlay()as a tenant or privilege boundary: it shares the parent environment's data except its cache and overridden attributes, and inherited extensions cannot be removed.
Output and trusted markup
- Pass untrusted values as template data and let autoescaping encode them