在jinja2(Flask)中Autoescape是默认的吗?

2024-09-30 16:37:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在研究一些网站的安全漏洞,想知道jinja2是否默认启用autoescape。根据Jinja的文档(http://jinja.pocoo.org/docs/2.9/faq/#why-is-autoescaping-not-the-default),它没有,但是当我在一个新系统上测试这个应用时,它被启用了(虽然我可能是不小心做了这个,但不确定)。在

有人能照一下这个吗?在


Tags: 文档orghttpjinja2docsis网站jinja
1条回答
网友
1楼 · 发布于 2024-09-30 16:37:27

{根据^ a1:

除定制外,Jinja2按烧瓶配置如下:

autoescaping is enabled for all templates ending in .html, .htm, .xml as well as .xhtml when using render_template().

同时:

autoescaping is enabled for all strings when using render_template_string().

最后:

a template has the ability to opt in/out autoescaping with the {% autoescape %} tag.

因此,虽然jinja在默认情况下可能不会自动转义,但flask默认打开Jinja的自动转义。在

相关问题 更多 >