CVE-2026-54691
SSRF vulnerability in datamodel-code-generator via unvalidated URL targets.
- CVSS 8.2
- 918
- Input Validation and Sanitization
- Remote
datamodel-code-generator generates Python data models from schema definitions. From 0.9.1 until 0.61.0, src/datamodel_code_generator/http.py http.get_body accepts –url targets and redirect chain targets without host/IP validation, allowing server-side request forgery against loopback, private, link-local, metadata, and other network-accessible resources. This issue is fixed in version 0.61.0.
- CWE
- 918
- CVSS base score
- 8.2
- Published
- 2026-07-28
- OWASP
- A10 Server-Side Request Forgery (SSRF)
- Orthogonal defect classification
- Checking
- Code defect classification
- Missing Check
- Category
- Input Validation and Sanitization
- Subcategory
- Server-Side Request Forgery (SSRF)
- Accessibility scope
- Remote
- Impact
- Information Disclosure
- Affected component
- datamodel-co
- Fixed by upgrading
- Yes
Solution
Upgrade datamodel-code-generator to version 0.16.0 or later.
Vulnerable code sample
import urllib.parse
from typing import Dict, Optional
import requests
from requests import Session
def get_body(
url: str,
headers: Optional[Dict[str, str]] = None,
ignore_tls: bool = False,
) -> str:
parsed_url = urllib.parse.urlparse(url)
if parsed_url.scheme not in ("http", "https"):
raise ValueError("URL scheme must be http or https")
with Session() as session:
# VULNERABLE: The URL is fetched without validation of the host, allowing server-side request forgery.
response = session.get(url, headers=headers, verify=not ignore_tls)
response.raise_for_status()
return response.textPatched code sample
import ipaddress
import socket
import urllib.parse
from typing import Dict, Optional
import requests
from requests import Session
class DisallowedHostError(Exception):
pass
def _validate_host(host: Optional[str]) -> None:
if not host:
return
try:
resolved_ip = socket.gethostbyname(host)
ip = ipaddress.ip_address(resolved_ip)
if ip.is_loopback or ip.is_private or ip.is_link_local:
raise DisallowedHostError(
f"Host '{host}' resolves to a disallowed IP address: {resolved_ip}"
)
except socket.gaierror as e:
raise DisallowedHostError(f"Host '{host}' could not be resolved.") from e
def get_body(
url: str,
headers: Optional[Dict[str, str]] = None,
ignore_tls: bool = False,
) -> str:
parsed_url = urllib.parse.urlparse(url)
if parsed_url.scheme not in ("http", "https"):
raise ValueError("URL scheme must be http or https")
# FIX: The hostname is resolved and checked against a blocklist of internal/private IP ranges.
_validate_host(parsed_url.hostname)
with Session() as session:
response = session.get(url, headers=headers, verify=not ignore_tls)
response.raise_for_status()
return response.textPayload
datamodel-codegen --url http://169.254.169.254/latest/meta-data/ --output mymodel.py
Cite this entry
@misc{vaitp:cve202654691,
title = {{SSRF vulnerability in datamodel-code-generator via unvalidated URL targets.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-54691},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-54691/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
