The analysis is based on the diff obtained from fetching the content of the commit URL https://github.com/Shopify/ejson2env/commit/592b3ceea967fee8b064e70983e8cec087b6d840, as the get_commit_infos tool did not return structured commit information. The vulnerability lies in insufficient input sanitization of environment variable keys and values, leading to potential command injection when the output of ejson2env is evaluated.
The identified functions (ExportEnv, ExportQuiet, and the internal escape function) were directly involved in processing these keys and values and constructing the output strings in their pre-patch versions.
ExportEnv and ExportQuiet took the map of keys and values, formatted them into strings, and wrote them to the output. Their previous implementations used keys directly in fmt.Sprintf and relied on the escape function for values, followed by regex-based validation (ValidateExportCommand/ValidateQuietCommand) which proved insufficient.
- The
escape function was responsible for sanitizing the values. Its previous implementation, using unicode.IsControl for filtering and shell.Escape for escaping, was inadequate.
The patch significantly refactored these functions, introduced explicit key validation (validKey), and changed the value sanitization mechanism (filteredValue using a different escaping library), indicating that the prior versions of ExportEnv, ExportQuiet, and escape were the source of the vulnerability.