Summary
Elo's Ruby backend can emit attacker-controlled text inside Ruby double-quoted strings without neutralizing Ruby interpolation syntax. If the resulting Ruby is evaluated, crafted expressions may execute Ruby code, including shell commands; this issue is specific to Ruby emission.
Affected context
The issue occurs in Elo's Ruby backend when it generates Ruby source from expressions containing attacker-controlled text. Relevant entry points include the /try playground when Ruby is selected, bin/eloc -t ruby -x, and defaultFormats.elo.parse() followed by Ruby emission. Risk depends on whether an attacker can supply or influence expressions and whether the generated Ruby is subsequently run. The described Ruby-specific path does not affect JavaScript, Python, or SQL emission.
Exploit preconditions
- Attack surface: An Elo expression is processed through a Ruby-emission entry point.
- Required access: Ability to submit or influence expression text; whether this is unauthenticated depends on how the entry point is exposed.
- Trigger point: Generated Ruby is evaluated. A failing labelled subtype constraint can evaluate its message; an ordinary string literal can be evaluated when the compiled Ruby runs.
- Why exploitation is possible: Attacker-controlled text is emitted into Ruby double-quoted strings without escaping interpolation syntax.
Why this happens
The Ruby emitter places text into double-quoted Ruby string literals without correctly escaping # and other syntax relevant to interpolation. Ruby may interpret embedded expressions when the generated code runs, turning data into executable logic. This is primarily CWE-94: Improper Control of Generation of Code, with CWE-116: Improper Encoding or Escaping of Output and CWE-1336: Improper Neutralization of Special Elements Used in a Template Engine describing related aspects of the unsafe code-generation boundary.
Potential impact
- Attacker-controlled expressions could cause arbitrary Ruby code to run in the process executing the generated output.
- The running process could execute shell commands with its existing privileges.
- Application data or runtime resources could be accessed or modified, depending on the execution environment.
- Other language targets are not affected by this Ruby-specific emission path.
General mitigation guidance
Mitigation generally focuses on keeping expression data separate from generated code and ensuring generated output cannot reinterpret data as Ruby syntax.
- Prefer code-generation approaches that avoid interpolating untrusted text into executable string literals.
- Apply context-appropriate escaping or use safe literal-construction APIs for Ruby output.
- Validate expression structure against a strict schema, while treating validation as a complement to safe emission.
- Limit who can submit expressions and where generated Ruby can be executed.
- Run generated code with least privilege and restrict its access to sensitive files, credentials, and system resources.
How teams detect issues like this
- Use static analysis to identify attacker-controlled values concatenated or interpolated into generated Ruby source.
- Review Ruby string-literal emitters and subtype-constraint message handling for context-aware escaping.
- Add tests that verify special characters remain inert in generated output and cannot become Ruby interpolation.
- Enforce code-generation policies in review and CI, including checks that untrusted expression text is not emitted as executable syntax.
- Automated code review tools may help flag unsafe source-generation patterns.

