CVE-2026-59862: Kiota: Code Generation Literal Injection in the Python Generator

Published Jul 16, 2026
·
Updated

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.

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.

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

Patches

https://github.com/microsoft/kiota/pull/7735

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

Other sources

Kiota is an OpenAPI based HTTP Client code generator. Prior to 1.29.1 and 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.29.1 and 1.32.0.

MITRE

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.

NVD

Affected Software

3 affected componentsFixes available
Kiota Kiota<1.32.0
nuget/Microsoft.OpenAPI.Kiota.Builder<1.32.0
1.32.0
nuget/Microsoft.OpenAPI.Kiota<1.32.0
1.32.0

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade nuget/Microsoft.OpenAPI.Kiota.Builder to a version that resolves this vulnerability.

    Fixed in 1.32.0
  2. Upgrade

    Upgrade nuget/Microsoft.OpenAPI.Kiota to a version that resolves this vulnerability.

    Fixed in 1.32.0
  3. Upgrade

    Upgrade Kiota (Python generator) to a version that resolves this vulnerability.

    Fixed in 1.29.1
  4. Upgrade

    Upgrade Kiota (Python generator) to a version that resolves this vulnerability.

    Fixed in 1.32.0
  5. Configuration

    Disable or gate automatic generation of Python clients from OpenAPI specifications hosted at attacker-controlled or external URLs in CI/CD; generate only from trusted, internally controlled OpenAPI specification sources.

    KiotaBuilder / Python generator (CI/CD generation) automatic generation from remote specs = disabled_or_gated
  6. Compensating control

    Run Kiota generation and validation in isolated environments without access to production secrets (so injected code at import time cannot exfiltrate secrets).

  7. Operational

    Regenerate existing Python clients using Kiota after upgrading to replace previously generated vulnerable output.

  8. Operational

    Confirm malicious multi-line enum descriptions no longer produce executable top-level output by running generation and validation on a proof-of-concept spec that previously demonstrated the issue.

  9. Operational

    Review generated Python files for suspicious top-level statements near enum/model declarations.

Event History

Jul 16, 2026
CVE Published
via MITRE·02:38 PM
Data Sourced
via MITRE·02:38 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·03:16 PM
DescriptionSeverityWeakness
Jul 24, 2026
Advisory Published
via GitHub·03:45 PM
Data Sourced
via GitHub·03:45 PM
DescriptionSeverityWeaknessAffected Software
Free Weekly Intel

Don't miss critical vulnerabilities

Join thousands of security professionals who receive our weekly digest of trending CVEs, zero-days, and exploited vulnerabilities.

No spam. Unsubscribe anytime.

Frequently Asked Questions

1

What is the severity of CVE-2026-59862?

The severity of CVE-2026-59862 is categorized as high with a score of 7.5.

2

What type of vulnerability is CVE-2026-59862?

CVE-2026-59862 is classified as a Code Injection vulnerability.

3

How do I fix CVE-2026-59862?

To mitigate CVE-2026-59862, upgrade to Kiota version 1.32.0 or later.

4

Which software is affected by CVE-2026-59862?

CVE-2026-59862 affects the Kiota HTTP Client code generator.

5

What impact does CVE-2026-59862 have?

CVE-2026-59862 can lead to potential risks associated with unauthorized code execution through injected enum value descriptions.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203