ci: add input sanitization for PR comment arguments#1229
Conversation
Validate and shell-quote arguments extracted from /gcbrun PR comments before
passing them to the GKE experiment pipeline.
In ci_trial_build.py, each token from the PR comment body is now checked
against a character allowlist. Any argument that contains shell metacharacters
(; & | ` $ ( ) { } < > " ') causes the entire command to be rejected and
logged as a warning. This prevents untrusted comment input from reaching the
Kubernetes job template substitution step.
In request_pr_exp.py, the additional_args list is joined using shlex.quote()
so that special characters within individual arguments are treated as literals
by the bash -c interpreter that runs the Kubernetes Job command string.
These changes harden the CI pipeline against unexpected argument values
without altering the existing behavior for well-formed inputs.
|
@google/oss-fuzz-gen-maintainers — Could someone review this patch? |
|
Hi @DonggeLiu, could you please review this patch when you get a chance? This addresses a command injection vulnerability in the /gcbrun PR comment dispatcher — unsanitized arguments from PR comments were passed directly into a Kubernetes Job template that executes a bash -c command string. The fix adds an allowlist validator in ci_trial_build.py and shlex.quote() escaping in request_pr_exp.py. The Google security team has acknowledged the patch (OSS VRP) and is waiting for a merge confirmation before proceeding with their evaluation. I appreciate your time! Regard, |
Validate and shell-quote arguments extracted from /gcbrun PR comments
before passing them to the GKE experiment pipeline.
In
ci/ci_trial_build.py, each token from the PR comment body is nowchecked against a character allowlist (
[a-zA-Z0-9_\-\.\/,=:@]). Anyargument that contains characters outside this set causes the entire
command to be rejected and logged as a warning. This prevents unexpected
input from reaching the Kubernetes job template substitution step.
In
ci/request_pr_exp.py, theadditional_argslist is now joinedusing
shlex.quote()so that special characters within individualarguments are treated as literals by the
bash -cinterpreter thatruns the Kubernetes Job command string. This acts as a second layer of
defense covering both
ci/k8s/pr-exp.yamlandci/k8s/large-pr-exp.yaml.Files changed:
ci/ci_trial_build.py: Added_SAFE_ARG_PATTERNallowlist and_sanitize_shell_arg()validator; updatedget_latest_gcbrun_command()to reject commands containing disallowed characters.
ci/request_pr_exp.py: Addedshleximport and shell-quoting foradditional_argsbefore template substitution.