CVE-2026-59862
Code injection in Kiota Python generator via unsanitized enum descriptions.
- CVSS 7.5
- CWE-94
- Input Validation and Sanitization
- Local
Kiota is an OpenAPI based HTTP Client code generator. Prior to 1.32.0, Kiota's Python generator let attacker-controlled enum value descriptions from x-ms-enum.values[].description flow through KiotaBuilder.SetEnumOptions into Documentation.DescriptionTemplate and PythonConventionService.RemoveInvalidDescriptionCharacters without newline sanitization, allowing generated inline comments to split and execute attacker-controlled Python code at module scope when generated modules were imported. This issue is fixed in version 1.32.0.
- CWE
- CWE-94
- CVSS base score
- 7.5
- Published
- 2026-07-16
- OWASP
- A08 Software and Data Integrity Failures
- Orthogonal defect classification
- Checking
- Code defect classification
- Missing Check
- Category
- Input Validation and Sanitization
- Subcategory
- Command Injection
- Accessibility scope
- Local
- Impact
- Arbitrary Code Execution
- Affected component
- Kiota
- Fixed by upgrading
- Yes
Solution
Upgrade Kiota to version 1.32.0 or later.
Vulnerable code sample
# This script simulates the vulnerable behavior of the Kiota generator before the fix.
# It demonstrates how an unsanitized description from an OpenAPI specification
# can lead to code injection in the generated Python client.
# 1. Attacker-controlled data mimicking part of an OpenAPI specification.
# The 'description' field contains a newline character ('\n') followed by
# malicious Python code.
malicious_spec_part = {
"name": "InjectedEnum",
"values": [
{
"name": "HARMLESS_MEMBER",
"description": "This is a normal description."
},
{
"name": "MALICIOUS_MEMBER",
# The description contains a newline to break out of the comment
# and inject a new line of executable Python code.
"description": "Malicious description.\nimport os; os.system('echo CVE-2026-59862 TRIGGERED') # Injected"
}
]
}
def vulnerable_code_generator(spec):
"""
A simplified simulation of the vulnerable Kiota generator logic.
It does not sanitize newlines in descriptions, leading to the vulnerability.
"""
lines = [
"from enum import Enum",
"",
f"class {spec['name']}(Enum):"
]
for value in spec['values']:
# The vulnerability is here: `description` is not sanitized.
# A newline character within it will create a new line in the output file.
description = value['description']
member_name = value['name']
# The generator intends for the description to be an inline comment.
line = f' {member_name} = "{member_name.lower()}" # {description}'
lines.append(line)
return "\n".join(lines)
# 2. The generator is run, creating the malicious code string.
# In a real attack, this string would be written to a .py file.
generated_code_string = vulnerable_code_generator(malicious_spec_part)
# 3. The output shows the generated code. When saved to a file and imported,
# the `import os...` line is no longer a comment and will be executed.
print(generated_code_string)Patched code sample
import re
def sanitize_for_inline_comment(description: str) -> str:
"""
Sanitizes a string to be safely included in a single-line Python comment,
representing the fix for the newline injection vulnerability.
The vulnerability (CVE-2023-49862) occurred because newline characters
in a description were not sanitized. This allowed an attacker to craft
a multi-line string that would break out of a generated comment and be
executed as Python code.
This function neutralizes the threat by replacing newline and carriage
return characters with a space, ensuring the entire description remains
on a single, non-executable comment line.
Args:
description: The raw string from a source like an OpenAPI description.
Returns:
A sanitized string safe for use in a generated inline comment.
"""
if not description:
return ""
# The core of the fix: replace any newline or carriage return characters
# with a space to prevent comment injection.
return re.sub(r'[\r\n]', ' ', description)Payload
\nimport os; os.system('touch /tmp/pwned') #
Cite this entry
@misc{vaitp:cve202659862,
title = {{Code injection in Kiota Python generator via unsanitized enum descriptions.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-59862},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-59862/}}
}
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 ::
