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#@varwere 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.

