Summary
Microsoft Kiota: Code Generation Literal Injection in Kiota Python Generator
Code Generation Literal Injection in Kiota Python Generator Leads to Arbitrary Code Execution at Import Time.
The Kiota Python code generator is vulnerable to a code generation literal injection issue when processing malicious or untrusted OpenAPI specifications. Specifically, attacker-controlled enum value descriptions from x-ms-enum.values[].description can flow into generated Python files without newline sanitization, allowing injected content to escape a comment context and execute at module scope when the generated module is imported.
This issue requires user interaction in the form of generating a client from a malicious specification and importing the generated code, which is a common development and CI workflow.
Potential impact includes
Credential theft from developer or CI environments
Exfiltration of environment variables and secrets
Source code disclosure
Persistence via regenerated backdoored client output
Who is impacted
Developers generating Python SDKs from external or untrusted OpenAPI specs
Teams with CI/CD automation that regenerates clients from remote specification URLs
Any environment importing generated Python modules before manual review
Vulnerability details
Two gaps combine to enable exploitation:
Enum description cleanup gap
In KiotaBuilder.SetEnumOptions, enum option descriptions are assigned to Documentation.DescriptionTemplate without CleanupDescription on this path, allowing control characters such as newlines to propagate.
Python description sanitization gap
PythonConventionService.RemoveInvalidDescriptionCharacters escapes backslashes and triple quotes but did not remove carriage return/newline characters, unlike some other language convention services.
Exploit path
Malicious newline in x-ms-enum description is emitted through enum writing path.
Generated inline comment output is split by newline.
Subsequent attacker-controlled line lands at module scope in generated .py file.
Importing the module executes the injected code.
Attack vectors
OpenAPI specifications hosted at attacker-controlled URLs
Supply-chain scenarios where third-party specs are consumed automatically
CI pipelines that generate and then import or test generated Python clients
Workarounds
If you cannot upgrade immediately:
Only generate from trusted, internally controlled OpenAPI specification sources.
Disable or gate automatic generation from remote specs in CI/CD.
Add validation/sanitization for x-ms-enum descriptions before generation.
Review generated Python files for suspicious top-level statements near enum/model declarations.
Run generation and validation in isolated environments without access to production secrets.
Remediation
Upgrade to Kiota 1.32.0 or later.
Regenerate existing Python clients to replace previously generated vulnerable output.
Recommended validation after upgrade
Regenerate from the same spec used in proof-of-concept testing
Confirm malicious multi-line enum descriptions no longer produce executable top-level output
Impact
A malicious OpenAPI specification can cause arbitrary Python code to be emitted into generated model files. The payload executes when the affected module is imported.
Untrusted input is evaluated as executable code within the application's runtime environment. Typical impact: arbitrary code execution within the application's privilege context.
CVE-2026-59862 has a CVSS score of 7.5 (High). The vector is network-reachable, no privileges required, and no user interaction. A CVSS score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether this affects your application depends on whether the vulnerable code is present and reachable in your environment. A fixed version is available (1.32.0); upgrading removes the vulnerable code path.
Affected versions
Security releases
Kodem intelligence
Severity tells you how bad this could be in the worst case. It does not tell you whether you are exposed. Exploitability and impact are functions of runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A vulnerable package can sit in your dependency tree and never run.
Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter. Kodem's runtime-powered SCA identifies whether this CVE is reachable in your applications.
Already deployed Kodem?
See it in your environmentNew to Kodem? Get a demo →Remediation advice
Frequently Asked Questions
- What is CVE-2026-59862? CVE-2026-59862 is a high-severity code injection vulnerability in Microsoft.OpenAPI.Kiota (nuget), affecting versions < 1.32.0. It is fixed in 1.32.0. Untrusted input is evaluated as executable code within the application's runtime environment.
- How severe is CVE-2026-59862? CVE-2026-59862 has a CVSS score of 7.5 (High). This score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether it represents real risk in your environment depends on whether the vulnerable code is present and reachable.
- Which packages are affected by CVE-2026-59862?
Microsoft.OpenAPI.Kiota(nuget) (versions < 1.32.0)Microsoft.OpenAPI.Kiota.Builder(nuget) (versions < 1.32.0)
- Is there a fix for CVE-2026-59862? Yes. CVE-2026-59862 is fixed in 1.32.0. Upgrade to this version or later.
- Is CVE-2026-59862 exploitable, and should I be worried? Whether CVE-2026-59862 is exploitable in your environment depends on whether the vulnerable code is present and reachable. A CVSS score is a worst-case rating; it does not account for your specific deployment, configuration, or usage patterns. Kodem, an Intelligent Application Security platform, uses runtime intelligence to show which vulnerabilities actually execute in production, so you can focus on the ones that represent real risk. Get a demo
- What actually determines whether CVE-2026-59862 is exploitable, and how bad it is? Exploitability and impact are not fixed properties of a CVE. They depend on runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A high CVSS score on a dependency that never runs is not the same as real risk. Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter.
- How do I fix CVE-2026-59862?
- Upgrade
Microsoft.OpenAPI.Kiotato 1.32.0 or later - Upgrade
Microsoft.OpenAPI.Kiota.Builderto 1.32.0 or later
- Upgrade