/

CVE-2026-59861

Severity:

HIGH RISK

(7.5)

Code Injection (CWE-94) in Kiota Ruby Client Generator

CVE-2026-59861

Deferred

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

Impact:

Arbitrary Code Execution in Generated Ruby Clients

Severity:

HIGH RISK

(7.5)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

The Kiota Ruby generator previously embedded attacker-controlled OpenAPI strings into Ruby double-quoted literals without escaping interpolation markers.

If an attacker can influence an OpenAPI document consumed by Kiota, they may inject arbitrary Ruby code into the generated client model classes.

Affected context

This vulnerability affects projects that use Kiota to generate Ruby HTTP client code from OpenAPI specifications.

It becomes relevant when OpenAPI documents contain fields such as default values, property names, or other schema-derived strings that are treated as trusted input by the generator.

In environments where OpenAPI specifications can be modified by untrusted parties—directly or via upstream dependencies—generated Ruby model classes may end up containing attacker-controlled interpolation sequences.

Exploit preconditions

  • Attack surface: The OpenAPI specification or schema files used as input to the Kiota Ruby generator.
  • Required access: Ability to create, modify, or influence the OpenAPI document consumed by the generation pipeline (e.g., via a compromised spec repository, third-party API description, or supply-chain tampering).
  • Trigger point: Running Kiota to generate Ruby client code and subsequently loading or executing the generated Ruby model classes in an application.
  • Why exploitation is possible: The generator interpolated unescaped schema-derived strings into Ruby double-quoted literals, so attacker-controlled sequences like #{expr}, #$var, or #@var were interpreted as Ruby interpolation at runtime, enabling execution of arbitrary Ruby code.

Why this happens

The underlying issue is unsafe handling of untrusted text when generating executable source code, mapping to CWE-94: Improper Control of Generation of Code ('Code Injection').

In Kiota's Ruby generator, logic in CodeMethodWriter.cs and SanitizeForQuotedLiteral() in Writers/StringExtensions.cs inserted strings derived from the OpenAPI schema into Ruby double-quoted string literals without escaping Ruby interpolation markers.

Because Ruby evaluates #{...} and related patterns inside double-quoted strings, this pattern effectively allowed input data to be treated as code.

The bug is conceptual: the generator assumed schema-derived strings were passive text, but Ruby's string interpolation semantics turned them into a code execution vector when not strictly sanitized or encoded.

Potential impact

  • Execution of arbitrary Ruby code within the context of applications using the generated client.
  • Compromise of application integrity, including modification of data returned by or sent through the client.
  • Exfiltration of sensitive information available to the Ruby process (e.g., credentials, tokens, configuration).
  • Escalation of an upstream supply-chain compromise, where tampered OpenAPI documents poison all downstream generated clients.

General mitigation guidance

Effective mitigation focuses on treating all schema-derived strings as untrusted and ensuring they cannot alter program semantics when emitted as code.

Common defensive patterns include:

  • Escaping or encoding interpolation markers and other metacharacters before placing user-controlled text into Ruby string literals.
  • Preferring single-quoted strings or other non-interpolated constructs in generated code when embedding externally-sourced text.
  • Introducing a strict sanitization layer for all specification-derived strings, using a centralized, well-reviewed function that neutralizes language-specific code injection vectors.
  • Reducing trust boundaries around OpenAPI inputs by controlling who can modify specifications and by validating them in CI/CD before code generation.
  • Running generated code with least-privilege configurations and isolating it where feasible so that any unexpected behavior has limited blast radius.

How teams detect issues like this

Detection strategies typically focus on both build-time and code-review time signals:

  • Static analysis rules targeting Ruby source to flag double-quoted strings containing unescaped, externally-derived content, particularly in generated files.
  • Generator-level checks that scan OpenAPI fields for interpolation markers such as #{, #$, or #@ and fail the build or raise warnings when found.
  • Code review guidelines that require inspection of generated code patterns, especially where schema-derived values are embedded into executable constructs.
  • Use of automated security scanning tools (SAST or specialized linters) integrated into CI pipelines to detect suspicious string interpolation patterns in client libraries.
  • Provenance checks and integrity controls around OpenAPI documents, such as signed specifications or checksums, to detect unexpected changes.

Sources

SourceLink
github.comgithub.com/microsoft/kiota/commit/fee1b648bb4394ba7ba72de9c0ce4f2a0bad0cb6
github.comgithub.com/microsoft/kiota/pull/7746
github.comgithub.com/microsoft/kiota/releases/tag/v1.32.0
github.comgithub.com/microsoft/kiota/security/advisories/GHSA-xg2h-5xr2-29jw

Frequently asked

questions

It can be, depending on how the OpenAPI specification is sourced. If an attacker can remotely influence the spec (for example through a compromised upstream service, repository, or API description feed) and the generated client is then used in production, the resulting code may execute attacker-controlled Ruby.

An attacker must be able to modify or control the OpenAPI document used by Kiota for Ruby code generation. This could be direct write access to a spec repo, the ability to submit or alter an API description in a shared environment, or control over a dependency that provides OpenAPI definitions.

The safest pattern is to ensure that no untrusted text is ever emitted into an interpolated context. This typically means escaping interpolation markers in specification-derived strings, using single-quoted strings where possible, and centralizing sanitization logic so all generator outputs are consistently neutralized before forming code.

Future prevention relies on secure code generation practices: design generators with explicit trust boundaries, treat all external specification data as untrusted, apply language-aware escaping rules, and enforce security-focused code reviews and automated checks on both the generator and its outputs. Additionally, validate and protect OpenAPI specifications as critical supply-chain artifacts.

Find out what's already
exploitable in your codebase.