python
config_error
ai_generated
true
jinja2.exceptions.SecurityError: 自动转义已禁用,但使用了 Markup
jinja2.exceptions.SecurityError: autoescape is disabled, but Markup is used
ID: python/flask-jinja-autoescape-off
80%修复率
82%置信度
0证据数
2024-07-07首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
在自动转义禁用的情况下对不可信数据使用 Markup 或 |safe,Jinja 在严格模式下抛出安全错误。
English
Using Markup or |safe on untrusted data with autoescape disabled, Jinja raises a security error in strict mode.
解决方案
-
93% 成功率
app.jinja_env.autoescape = select_autoescape(['html', 'xml'])
-
90% 成功率
Sanitize with bleach.clean(html, tags=[...]) before marking safe
无效尝试
常见但无效的做法:
-
50% 失败
Breaks legitimate HTML rendering; templates show escaped tags.
-
80% 失败
Unrelated setting; error persists.