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 package | Versions | Reported by |
|---|---|---|
| samuelcolvin pydantic | >= 1.8.0, < 1.8.2, >= 1.7.0, < 1.7.4, < 1.6.2 | CVE List |
| pydantic (PyPI) | before 1.6.2, from 1.8 before 1.8.2, from 1.7 before 1.7.4, before 7e83fdd2563ffac081db7ecdf1affa65ef38c468 | GitHub Advisory Database, PyPA Advisory Database |
| pydantic pydantic | before 1.6.2, from 1.7 before 1.7.4, from 1.8 before 1.8.2 | NVD |
| fedoraproject fedora | 33, 34 | NVD |
All scores
| GitHub_M | 3.3low CVSS:3.1 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:L |
| GitHub | 3.3medium CVSS:3.1 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:L |
| GitHub | medium CVSS:4.0 | CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N |
| NVD | 7.5high CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H |
| NVD | 5.0medium CVSS:2.0 | AV: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
Sources
| Source | Record | Licence |
|---|---|---|
| CVE List | CVE-2021-29510 changed 2024-08-03 | CVE Terms of Use |
| GitHub Advisory Database | GHSA-5jqp-qgf6-3pvh changed 2026-07-08 | CC-BY-4.0 |
| NVD | CVE-2021-29510 changed 2026-06-17 | Public domain |
| PyPA Advisory Database | PYSEC-2021-47 changed 2026-06-08 | CC-BY-4.0 |