---
title: "Django 2.2.4 版本发行说明"
version: 4.2
locale: zh-hans
source: https://docs.djangoproject.com/zh-hans/4.2/releases/2.2.4/
canonical: https://djangodocs.dev/zh-hans/4.2/releases/2.2.4/
---
# Django 2.2.4 版本发行说明

*2019 年 8 月 1 日*

Django 2.2.4 修复了 Django 2.2.3 中的安全问题和若干个错误。

## CVE-2019-14232: `django.utils.text.Truncator` 中存在拒绝服务可能性问题。

如果 `django.utils.text.Truncator` 的 `chars()` 和 `words()` 方法传递了 `html=True` 参数，它们在处理某些输入时非常慢，这是由于正则表达式中的灾难性回溯漏洞引起的。`chars()` 和 `words()` 方法用于实现 [`truncatechars_html`](/zh-hans/4.2/ref/templates/builtins/#std-templatefilter-truncatechars_html) 和 [`truncatewords_html`](/zh-hans/4.2/ref/templates/builtins/#std-templatefilter-truncatewords_html) 模板过滤器，因此这两个过滤器也存在漏洞。

为了避免潜在的回溯问题，`Truncator` 使用的正则表达式已经简化。因此，尾部的标点符号可能会有时包含在截断后的输出中。

## CVE-2019-14233: `strip_tags()` 中存在拒绝服务可能性问题。

由于底层的 `HTMLParser` 的行为，[`django.utils.html.strip_tags()`](/zh-hans/4.2/ref/utils/#django.utils.html.strip_tags) 在处理包含大量嵌套不完整 HTML 实体序列的某些输入时会变得非常慢。`strip_tags()` 方法用于实现相应的 [`striptags`](/zh-hans/4.2/ref/templates/builtins/#std-templatefilter-striptags) 模板过滤器，因此这两个过滤器也存在漏洞。

现在，`strip_tags()` 在删除标签时避免了对 `HTMLParser` 的递归调用，但当进度停止删除标签但仍存在不完整的 HTML 实体时，它会继续运行。

请记住，`strip_tags()` 的结果绝对不保证是安全的 HTML。因此，在将 `strip_tags()` 调用的结果标记为安全之前，绝对不要忘记首先进行转义，例如使用 [`django.utils.html.escape()`](/zh-hans/4.2/ref/utils/#django.utils.html.escape)。

## CVE-2019-14234: 在 `JSONField`/`HStoreField` 的键和索引查找中存在 SQL 注入可能性。

`django.contrib.postgres.fields.JSONField` 的 [`键和索引查找`](/zh-hans/4.2/topics/db/queries/#std-fieldlookup-jsonfield.key)，以及 [`HStoreField`](/zh-hans/4.2/ref/contrib/postgres/fields/#django.contrib.postgres.fields.HStoreField) 的 [`键查找`](/zh-hans/4.2/ref/contrib/postgres/fields/#std-fieldlookup-hstorefield.key)，都受到了 SQL 注入的影响，使用适当构造的字典，并将其作为传递给 `QuerySet.filter()` 的 `**kwargs` 进行字典扩展。

## CVE-2019-14235: `django.utils.encoding.uri_to_iri()` 中存在潜在的内存耗尽问题。

如果传递了特定的输入，[`django.utils.encoding.uri_to_iri()`](/zh-hans/4.2/ref/utils/#django.utils.encoding.uri_to_iri) 在重新百分号编码无效的 UTF-8 八位序列时可能会导致显着的内存使用，因为它会发生过多的递归。

现在，`uri_to_iri()` 在重新百分号编码无效的 UTF-8 八位序列时避免了递归。

## 漏洞修复

- 修复了 Django 2.2 中的一个回归问题，当对一个包含多次出现的字段类型的 `QuerySet.union()`, `intersection()` 或 `difference()` 进行排序时，会导致使用错误的排序方式 ([#30628](https://code.djangoproject.com/ticket/30628))。
- 修复了在 PostgreSQL 上进行迁移时的崩溃问题，当在 [`DateRangeField`](/zh-hans/4.2/ref/contrib/postgres/fields/#django.contrib.postgres.fields.DateRangeField) 或 [`DateTimeRangeField`](/zh-hans/4.2/ref/contrib/postgres/fields/#django.contrib.postgres.fields.DateTimeRangeField) 上添加具有 `contains` 查找的检查约束时，如果表达式的右侧是相同类型的话 ([#30621](https://code.djangoproject.com/ticket/30621))。
- 修复了 Django 2.2 中的一个回归问题，如果文件路径包含空字符（`'\x00'`），自动重新加载器会崩溃的问题 ([#30506](https://code.djangoproject.com/ticket/30506))。
- 修复了 Django 2.2 中的一个回归问题，如果无法解析翻译目录，自动重新加载器会崩溃的问题 ([#30647](https://code.djangoproject.com/ticket/30647))。
