The analysis of the provided security advisory and commit patches confirms a code injection vulnerability within the @orval/mock package. The root cause is the improper handling of const values from an OpenAPI specification during mock data generation.
The vulnerable function is getMockScalar located in packages/mock/src/faker/getters/scalar.ts. The evidence from the commits (e.g., 6d8ece07ccb80693ad43edabccb3957aceadcd06) clearly shows that the value of item.const was being used in a string template without any sanitization. For example, the line value = '${(item as SchemaObject31).const}'; demonstrates the direct inclusion of the user-provided const value into the generated code.
The fix, applied across multiple commits, involves properly escaping this value. Initially, a jsStringEscape function was introduced, and later, this was replaced with the more robust JSON.stringify to ensure the const value is treated as a safe string literal. An attacker exploiting this vulnerability could craft an OpenAPI document with a malicious payload in a const field, leading to arbitrary code execution in the environment where the orval-generated mocks are used.