diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-10-17 11:48:32 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-11-01 06:10:30 +0100 |
| commit | 05ba4130ee878c4f520b5d34bb11eaad794623be (patch) | |
| tree | 1d11111ee476d411c8fc62bd6da6e9376d2f1d4e /django | |
| parent | 40b3975e7d3e1464a733c69171ad7d38f8814280 (diff) | |
Fixed CVE-2023-46695 -- Fixed potential DoS in UsernameField on Windows.
Thanks MProgrammer (https://hackerone.com/mprogrammer) for the report.
Diffstat (limited to 'django')
| -rw-r--r-- | django/contrib/auth/forms.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py index eaae0bf695..061dc81b42 100644 --- a/django/contrib/auth/forms.py +++ b/django/contrib/auth/forms.py @@ -71,7 +71,15 @@ class ReadOnlyPasswordHashField(forms.Field): class UsernameField(forms.CharField): def to_python(self, value): - return unicodedata.normalize("NFKC", super().to_python(value)) + value = super().to_python(value) + if self.max_length is not None and len(value) > self.max_length: + # Normalization can increase the string length (e.g. + # "ff" -> "ff", "½" -> "1⁄2") but cannot reduce it, so there is no + # point in normalizing invalid data. Moreover, Unicode + # normalization is very slow on Windows and can be a DoS attack + # vector. + return value + return unicodedata.normalize("NFKC", value) def widget_attrs(self, widget): return { |
