CVE-2026-59861: CWE-94: Improper Control of Generation of Code ('Code Injection') in microsoft kiota
Kiota is an OpenAPI based HTTP Client code generator. Prior to 1.29.1 and 1.32.0, Kiota's Ruby generator embedded OpenAPI default fields, property names, and other schema-derived strings through CodeMethodWriter.cs and SanitizeForQuotedLiteral() in Writers/StringExtensions.cs into Ruby double-quoted literals without escaping #, allowing attacker-controlled #{expr}, #$var, or #@var interpolation markers to inject arbitrary Ruby code into generated model classes. This issue is fixed in version 1.29.1 and 1.32.0.
AI Analysis
Technical Summary
The Kiota Ruby code generator improperly handles the # character in string literals derived from OpenAPI specification default fields and property names. Since Ruby evaluates expressions like #{expr} inside double-quoted strings, an attacker controlling the OpenAPI spec can inject arbitrary Ruby code into generated client models. The root cause is the SanitizeForQuotedLiteral() function failing to escape # characters. This vulnerability can lead to arbitrary code execution when the generated code is used, particularly in production environments. The issue affects Kiota versions prior to 1.32.0. Microsoft has released patches in versions 1.29.1 and 1.32.0 to address this problem. Workarounds include auditing and sanitizing OpenAPI specs, code reviewing generated files, restricting spec sources to trusted origins, isolating generated code from production, and manually escaping # characters if immediate upgrade is not possible.
Potential Impact
This vulnerability allows arbitrary Ruby code execution via malicious OpenAPI specifications when the generated Ruby client code is used. The severity is critical if the vulnerable generated code reaches production, high in CI/CD environments with access to production secrets, medium for public third-party specs, and low if specs are developer-controlled. Exploitation could lead to unauthorized code execution within the context of the generated client application.
Mitigation Recommendations
Upgrade Microsoft Kiota to version 1.29.1, 1.32.0, or later to apply the official fix. Regenerate all existing Ruby clients using the updated Kiota to replace vulnerable generated code. If immediate upgrade is not possible, audit and sanitize OpenAPI specification files to remove or replace # characters in default values and property names. Implement mandatory code reviews of generated Ruby files to detect suspicious string interpolation patterns. Restrict OpenAPI specs to trusted internal sources and avoid automatic generation from untrusted external specs. Do not deploy generated Ruby code to production unless the specification source is verified and reviewed. As a temporary measure, manually escape # characters in generated string literals by replacing # with \#.
CVE-2026-59861: CWE-94: Improper Control of Generation of Code ('Code Injection') in microsoft kiota
Description
Kiota is an OpenAPI based HTTP Client code generator. Prior to 1.29.1 and 1.32.0, Kiota's Ruby generator embedded OpenAPI default fields, property names, and other schema-derived strings through CodeMethodWriter.cs and SanitizeForQuotedLiteral() in Writers/StringExtensions.cs into Ruby double-quoted literals without escaping #, allowing attacker-controlled #{expr}, #$var, or #@var interpolation markers to inject arbitrary Ruby code into generated model classes. This issue is fixed in version 1.29.1 and 1.32.0.
CVSS v3.1
Score 7.5high
Affected software
Run on your own infrastructure? Check whether these packages are installed with threat-finder — our free open-source scanner.
Weaknesses
AI-Powered Analysis
Machine-generated threat intelligence
Technical Analysis
The Kiota Ruby code generator improperly handles the # character in string literals derived from OpenAPI specification default fields and property names. Since Ruby evaluates expressions like #{expr} inside double-quoted strings, an attacker controlling the OpenAPI spec can inject arbitrary Ruby code into generated client models. The root cause is the SanitizeForQuotedLiteral() function failing to escape # characters. This vulnerability can lead to arbitrary code execution when the generated code is used, particularly in production environments. The issue affects Kiota versions prior to 1.32.0. Microsoft has released patches in versions 1.29.1 and 1.32.0 to address this problem. Workarounds include auditing and sanitizing OpenAPI specs, code reviewing generated files, restricting spec sources to trusted origins, isolating generated code from production, and manually escaping # characters if immediate upgrade is not possible.
Potential Impact
This vulnerability allows arbitrary Ruby code execution via malicious OpenAPI specifications when the generated Ruby client code is used. The severity is critical if the vulnerable generated code reaches production, high in CI/CD environments with access to production secrets, medium for public third-party specs, and low if specs are developer-controlled. Exploitation could lead to unauthorized code execution within the context of the generated client application.
Mitigation Recommendations
Upgrade Microsoft Kiota to version 1.29.1, 1.32.0, or later to apply the official fix. Regenerate all existing Ruby clients using the updated Kiota to replace vulnerable generated code. If immediate upgrade is not possible, audit and sanitize OpenAPI specification files to remove or replace # characters in default values and property names. Implement mandatory code reviews of generated Ruby files to detect suspicious string interpolation patterns. Restrict OpenAPI specs to trusted internal sources and avoid automatic generation from untrusted external specs. Do not deploy generated Ruby code to production unless the specification source is verified and reviewed. As a temporary measure, manually escape # characters in generated string literals by replacing # with \#.
Technical Details
- Data Version
- 5.2
- Assigner Short Name
- GitHub_M
- Date Reserved
- 2026-07-07T15:41:53.606Z
- Cvss Version
- 3.1
- State
- PUBLISHED
- Remediation Level
- null
Threat ID: 6a58ef3568715ace4330614c
Added to database: 07/16/2026, 14:48:21 UTC
Last enriched: 08/17/2026, 16:25:17 UTC
Last updated: 08/30/2026, 00:21:44 UTC
Views: 96
Community Reviews
0 reviewsCrowdsource mitigation strategies, share intel context, and vote on the most helpful responses. Sign in to add your voice and help keep defenders ahead.
Want to contribute mitigation steps or threat intel context? Sign in or create an account to join the community discussion.
Actions
Updates to AI analysis require Pro Console access. Upgrade inside Console → Billing.
Need more coverage?
Upgrade to Pro Console for AI refresh and higher limits.
For incident response and remediation, OffSeq services can help resolve threats faster.
Latest Threats
Check if your credentials are on the dark web
Instant breach scanning across billions of leaked records. Free tier available.