The vulnerability is a command injection within the aquasecurity/trivy-action GitHub Action, introduced in commit 7aca5acc9500b463826cc47a47a65ad7d404b045. The vulnerability exists because user-supplied inputs are not properly sanitized before being written to a file that is later executed as a shell script.
The vulnerability has two main components:
- The Injection Sink: In
action.yaml, the shell function set_env_var_if_provided takes user inputs and writes them to a file named trivy_envs.txt. It uses the command echo "export $var_name=$input_value" >> trivy_envs.txt, which does not escape special shell characters in the $input_value. This allows an attacker to inject arbitrary shell commands into the trivy_envs.txt file.
- The Execution Trigger: In
entrypoint.sh, the command source ./trivy_envs.txt is used. This command reads the trivy_envs.txt file and executes its contents as a shell script. When the file contains malicious commands injected in the previous step, they are executed with the permissions of the GitHub Actions runner.
The patch, in commit bc61dc55704e2d5704760f3cdab0d09acf16e4ca, fixes the vulnerability by replacing the insecure echo command with printf 'export %s=%q\n' "$var_name" "$input_value". The %q format specifier in printf ensures that the input value is properly quoted and escaped, preventing it from being interpreted as shell commands.
During exploitation, a runtime profiler would show the entrypoint.sh script being executed, which in turn sources the malicious trivy_envs.txt file. The set_env_var_if_provided function is where the malicious payload is constructed.