CVE-2021-29510
JSON

3.3low

Use of "infinity" as an input to datetime and date fields causes infinite loop in pydantic

Severity
3.3low CVSS:3.1 by GitHub_M
Exploit likelihood
0.97% (higher than 63% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
GitHub_M
Also known as
GHSA-5jqp-qgf6-3pvhPYSEC-2021-47

Description

Pydantic is a data validation and settings management using Python type hinting. In affected versions passing either `'infinity'`, `'inf'` or `float('inf')` (or their negatives) to `datetime` or `date` fields causes validation to run forever with 100% CPU usage (on one CPU). Pydantic has been patched with fixes available in the following versions: v1.8.2, v1.7.4, v1.6.2. All these versions are available on pypi(https://pypi.org/project/pydantic/#history), and will be available on conda-forge(https://anaconda.org/conda-forge/pydantic) soon. See the changelog(https://pydantic-docs.helpmanual.io/) for details. If you absolutely can't upgrade, you can work around this risk using a validator(https://pydantic-docs.helpmanual.io/usage/validators/) to catch these values. This is not an ideal solution (in particular you'll need a slightly different function for datetimes), instead of a hack like this you should upgrade pydantic. If you are not using v1.8.x, v1.7.x or v1.6.x and are unable to upgrade to a fixed version of pydantic, please create an issue at https://github.com/samuelcolvin/pydantic/issues requesting a back-port, and we will endeavour to release a patch for earlier versions of pydantic.

Affected

Product or packageVersionsReported by
samuelcolvin pydantic>= 1.8.0, < 1.8.2, >= 1.7.0, < 1.7.4, < 1.6.2CVE List
pydantic (PyPI)before 1.6.2, from 1.8 before 1.8.2, from 1.7 before 1.7.4, before 7e83fdd2563ffac081db7ecdf1affa65ef38c468GitHub Advisory Database, PyPA Advisory Database
pydantic pydanticbefore 1.6.2, from 1.7 before 1.7.4, from 1.8 before 1.8.2NVD
fedoraproject fedora33, 34NVD

All scores

GitHub_M3.3low CVSS:3.1CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:L
GitHub3.3medium CVSS:3.1CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:L
GitHubmedium CVSS:4.0CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N
NVD7.5high CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
NVD5.0medium CVSS:2.0AV:N/AC:L/Au:N/C:N/I:N/A:P

Classification

What each source says

CVE List

Pydantic is a data validation and settings management using Python type hinting. In affected versions passing either `'infinity'`, `'inf'` or `float('inf')` (or their negatives) to `datetime` or `date` fields causes validation to run forever with 100% CPU usage (on one CPU). Pydantic has been patched with fixes available in the following versions: v1.8.2, v1.7.4, v1.6.2. All these versions are available on pypi(https://pypi.org/project/pydantic/#history), and will be available on conda-forge(https://anaconda.org/conda-forge/pydantic) soon. See the changelog(https://pydantic-docs.helpmanual.io/) for details. If you absolutely can't upgrade, you can work around this risk using a validator(https://pydantic-docs.helpmanual.io/usage/validators/) to catch these values. This is not an ideal solution (in particular you'll need a slightly different function for datetimes), instead of a hack like this you should upgrade pydantic. If you are not using v1.8.x, v1.7.x or v1.6.x and are unable to upgrade to a fixed version of pydantic, please create an issue at https://github.com/samuelcolvin/pydantic/issues requesting a back-port, and we will endeavour to release a patch for earlier versions of pydantic.

GitHub Advisory Database

Impact

Passing either 'infinity', 'inf' or float('inf') (or their negatives) to datetime or date fields causes validation to run forever with 100% CPU usage (on one CPU). Patches

Pydantic is be patched with fixes available in the following versions:

v1.8.2
v1.7.4
v1.6.2

All these versions are available on pypi, and will be available on conda-forge soon.

See the changelog for details. Workarounds

If you absolutely can't upgrade, you can work around this risk using a validator to catch these values, brief demo:

from datetime import date from pydantic import BaseModel, validator

class DemoModel(BaseModel): date_of_birth: date

@validator('date_of_birth', pre=True)
def skip_infinite_values(cls, v):
    try:
        seconds = float(v)
    except (ValueError, TypeError):
        return v
    else:
        if seconds == float('inf'):
            return date.max
        elif seconds == float('-inf'):
            return date.min
        else:
            return seconds

Note: this is not an ideal solution (in particular you'll need a slightly different function for datetimes), instead of a hack like this you should upgrade pydantic.

If you are not using v1.8.x, v1.7.x or v1.6.x and are unable to upgrade to a fixed version of pydantic, please create an issue requesting a back-port, and we will endeavour to release a patch for earlier versions of pydantic. References

This was fixed in commit 7e83fdd.

NVD (es)

Pydantic es un sistema de validación de datos y gestión de configuraciones que utiliza las sugerencias de tipo de Python. En las versiones afectadas, pasar `'infinity'`, `'inf'` o `float('inf')` (o sus negativos) a los campos `datetime` o `date` hace que la validación se ejecute eternamente con un uso del 100% de la CPU (en una CPU). Pydantic ha sido parcheado con correcciones disponibles en las siguientes versiones: v1.8.2, v1.7.4, v1.6.2. Todas estas versiones están disponibles en pypi(https://pypi.org/project/pydantic/#history), y estarán disponibles en conda-forge(https://anaconda.org/conda-forge/pydantic) pronto. Consulta el registro de cambios(https://pydantic-docs.helpmanual.io/) para más detalles. Si no puedes actualizar absolutamente, puedes evitar este riesgo usando un validador(https://pydantic-docs.helpmanual.io/usage/validators/) para capturar estos valores. Esta no es una solución ideal (en particular, necesitarás una función ligeramente diferente para las fechas), en lugar de un hack como este deberías actualizar pydantic. Si no estás usando v1.8.x, v1.7.x o v1.6.x y no puedes actualizar a una versión fija de pydantic, por favor crea un issue en https://github.com/samuelcolvin/pydantic/issues solicitando un back-port, y nos esforzaremos en liberar un parche para versiones anteriores de pydantic

References

https://github.com/samuelcolvin/pydantic/security/advisories/GHSA-5jqp-qgf6-3pvhadvisory, mitigation, patch, third-party-advisory, web
https://github.com/samuelcolvin/pydantic/commit/7e83fdd2563ffac081db7ecdf1affa65ef38c468fix, patch, third-party-advisory, web
https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/UMKAJX4O6IGBBCE32CO2G7PZQCCQSBLV/vendor-advisory
https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/S2HT266L6Q7H6ICP7DFGXOGBJHNNKMKB/vendor-advisory
https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/UEFWM7DYKD2ZHE7R5YT5EQWJPV4ZKYRB/vendor-advisory
https://nvd.nist.gov/vuln/detail/CVE-2021-29510advisory
https://github.com/pydantic/pydantic/commit/1c24f1d74ba95ea985b50bdc001ce96c813229aaweb
https://github.com/pydantic/pydantic/commit/80e0dd3f752bef145dce12f160d262bb40ec8d47web
https://github.com/pydantic/pydantic/commit/bdde15b7b947c94ca00fd6eb92da8db390a13520web
https://github.com/pydantic/pydanticpackage
https://github.com/pypa/advisory-database/tree/main/vulns/pydantic/PYSEC-2021-47.yamlweb
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/S2HT266L6Q7H6ICP7DFGXOGBJHNNKMKBweb

Sources

SourceRecordLicence
CVE ListCVE-2021-29510 changed 2024-08-03CVE Terms of Use
GitHub Advisory DatabaseGHSA-5jqp-qgf6-3pvh changed 2026-07-08CC-BY-4.0
NVDCVE-2021-29510 changed 2026-06-17Public domain
PyPA Advisory DatabasePYSEC-2021-47 changed 2026-06-08CC-BY-4.0