﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35675	Reduce impact of parsing crafted templates with repeat tags	Jake Howard	Hailey Johnson	"The template system uses a regex to extract template tags from text. Given certain inputs, this can take an excessive amount of time:

{{{#!python
In [2]: %timeit Template(""{%"" * 2000)
34.7 ms ± 153 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)

In [3]: %timeit Template(""{%"" * 10000)
877 ms ± 1.49 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

In [4]: %timeit Template(""{%"" * 20000)
3.49 s ± 47 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

In [5]: %timeit Template(""{%"")
11.5 µs ± 55.3 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
}}}

The cause is excessive backtracking in the [https://github.com/django/django/blob/b99c608ea10cabc97a6b251cdb6e81ef2a83bdcf/django/template/base.py#L89C23-L89C48 pattern used]. Since the template system is so versatile and performance-critical, fixing the issue appears non-trivial.

Note: This bug was raised with the Security Team prior to opening, however was not deemed a security vulnerability since parsing untrusted (or semi-trusted) templates is [https://docs.djangoproject.com/en/5.0/topics/templates/ explicitly warned against]."	Cleanup/optimization	assigned	Template system	dev	Normal				Accepted	1	0	1	0	0	0
