Vulnerabilities in pkg:pypi/pydantic
PACKAGECVE-2021-29510 is a MODERATE (CVSS 3.3) use of "infinity" as an vulnerability (CWE-835: Loop with Unreachable Exit Condition ('Infinite Loop')) affecting Pydantic libraries in the PyPI ecosystem. The issue involves use of "infinity" as an input to datetime and date fields causes infinite loop in pydantic. Remediation is available by upgrading affected packages to version 1.6.2, 1.8.2, 1.7.4.
pkg:pypi/pydantic
Vulnerability advisories affecting package pkg:pypi/pydantic. Select an advisory below to view technical details or fixes.
| Advisory ID | CVE / NVD | Severity | Summary |
|---|---|---|---|
| GHSA-5jqp-qgf6-3pvh | CVE-2021-29510 | MODERATE | Use of "infinity" as an input to datetime and date fields causes infinite loop in pydantic |
| GHSA-mr82-8j83-vxmv | CVE-2024-3772 | MODERATE | Pydantic regular expression denial of service |
CVE-2021-29510 at a Glance
Security Impact
CVSS: 3.3
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:L).
How to Fix CVE-2021-29510
To remediate this vulnerability, upgrade all affected Pydantic dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
pip install pydantic>=1.6.2
pip install pydantic>=1.8.2
pip install pydantic>=1.7.4
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
pip show pydantic
How to Check if You Are Affected
To determine whether your Python environment is affected by CVE-2021-29510, inspect your installed packages using pip:
pip show pydantic
Analyze the terminal output to locate any version of Pydantic in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.6.2), your application is affected.
Note: The pip show pydantic command checks currently installed packages in your active Python environment.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-835: Loop with Unreachable Exit Condition ('Infinite Loop'), where the product contains an iteration or loop with an exit condition that cannot be reached, i.e., an infinite loop. In Pydantic, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2021-29510 Affected Pydantic Versions
3 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
pydantic
|
PyPI |
< 1.6.2
|
1.6.2
|
|
pydantic
|
PyPI |
≥ 1.8
< 1.8.2
|
1.8.2
|
|
pydantic
|
PyPI |
≥ 1.7
< 1.7.4
|
1.7.4
|
References
Frequently Asked Questions
What is CVE-2021-29510?
Which Pydantic versions are affected?
What version fixes CVE-2021-29510?
Is pydantic affected?
What is the CVSS score of CVE-2021-29510?
What CWE is associated with CVE-2021-29510?
How can I check PyPI dependencies for CVE-2021-29510?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-5jqp-qgf6-3pvh",
"modified" : "2026-06-09T13:01:00Z",
"published" : "2021-05-13T20:23:17Z",
"aliases" : [ "CVE-2021-29510" ],
"summary" : "Use of \"infinity\" as an input to datetime and date fields causes infinite loop in pydantic",
"details" : "Impact\n\nPassing 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).\nPatches\n\nPydantic is be patched with fixes available in the following versions:\n\n v1.8.2\n v1.7.4\n v1.6.2\n\nAll these versions are available on pypi, and will be available on conda-forge soon.\n\nSee the changelog for details.\nWorkarounds\n\nIf you absolutely can't upgrade, you can work around this risk using a validator to catch these values, brief demo:\n\nfrom datetime import date\nfrom pydantic import BaseModel, validator\n\nclass DemoModel(BaseModel):\n date_of_birth: date\n\n @validator('date_of_birth', pre=True)\n def skip_infinite_values(cls, v):\n try:\n seconds = float(v)\n except (ValueError, TypeError):\n return v\n else:\n if seconds == float('inf'):\n return date.max\n elif seconds == float('-inf'):\n return date.min\n else:\n return seconds\n\nNote: 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.\n\nIf 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.\nReferences\n\nThis was fixed in commit 7e83fdd.",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:L"
}, {
"type" : "CVSS_V4",
"score" : "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"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "PyPI",
"name" : "pydantic"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "1.6.2"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "pydantic"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "1.8"
}, {
"fixed" : "1.8.2"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "pydantic"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "1.7"
}, {
"fixed" : "1.7.4"
} ]
} ]
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/samuelcolvin/pydantic/security/advisories/GHSA-5jqp-qgf6-3pvh"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-29510"
}, {
"type" : "WEB",
"url" : "https://github.com/pydantic/pydantic/commit/1c24f1d74ba95ea985b50bdc001ce96c813229aa"
}, {
"type" : "WEB",
"url" : "https://github.com/pydantic/pydantic/commit/80e0dd3f752bef145dce12f160d262bb40ec8d47"
}, {
"type" : "WEB",
"url" : "https://github.com/pydantic/pydantic/commit/bdde15b7b947c94ca00fd6eb92da8db390a13520"
}, {
"type" : "WEB",
"url" : "https://github.com/samuelcolvin/pydantic/commit/7e83fdd2563ffac081db7ecdf1affa65ef38c468"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/pydantic/pydantic"
}, {
"type" : "WEB",
"url" : "https://github.com/pypa/advisory-database/tree/main/vulns/pydantic/PYSEC-2021-47.yaml"
}, {
"type" : "WEB",
"url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/S2HT266L6Q7H6ICP7DFGXOGBJHNNKMKB"
}, {
"type" : "WEB",
"url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/UEFWM7DYKD2ZHE7R5YT5EQWJPV4ZKYRB"
}, {
"type" : "WEB",
"url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/UMKAJX4O6IGBBCE32CO2G7PZQCCQSBLV"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-835" ],
"severity" : "MODERATE",
"github_reviewed" : true,
"github_reviewed_at" : "2021-05-13T18:54:35Z",
"nvd_published_at" : "2021-05-13T19:15:00Z"
}
}