Skip to content

security: ci: pass the merged pull request title to git commit as data - #237

Open
Shengcun-Scanner wants to merge 1 commit into
ALLTERCO:mainfrom
Shengcun-Scanner:shengcun/cicd-shell-injection-head-ref
Open

Shengcun-Scanner wants to merge 1 commit into
ALLTERCO:mainfrom
Shengcun-Scanner:shengcun/cicd-shell-injection-head-ref

Conversation

@Shengcun-Scanner

Copy link
Copy Markdown

The manifest sync job runs after a pull request is merged and puts the PR title
straight into the commit command:

- name: Synchronize manifest
  run: |
    …
    git diff --cached --quiet || git commit -m "Sync manifest (${{ github.event.pull_request.title }})"
    git push

The expression is expanded before bash parses the line, so the double quotes are
script text. A pull request titled

fix $(id)

runs that command in a pull_request_target job — the event that gets the base
repository's credentials rather than the fork's. The command runs before the
git push below it; whether that push then succeeds depends on the repository's
default token permissions, which this workflow does not declare.

The job is if: … merged == true, so the title only reaches the shell once a
maintainer merges. That is this job's normal trigger, and a commit-message
template is not where anyone looks for code.

Fix

- name: Synchronize manifest
  env:
    PR_TITLE: ${{ github.event.pull_request.title }}
  run: |
    …
    git diff --cached --quiet || git commit -m "Sync manifest ($PR_TITLE)"
    git push

The commit message is byte-identical for a normal title; the title is a variable
instead of script.

Verification

$ T='fix $(touch /tmp/pwned)'
$ bash -c "true -m \"Sync manifest ($T)\""    # before
$ ls /tmp/pwned
/tmp/pwned
$ rm /tmp/pwned
$ PR_TITLE="$T" bash -c 'true -m "Sync manifest ($PR_TITLE)"'   # after
$ ls /tmp/pwned
ls: cannot access '/tmp/pwned': No such file or directory
$ PR_TITLE='fix: typo in PlugPro example' bash -c 'echo "Sync manifest ($PR_TITLE)"'
Sync manifest (fix: typo in PlugPro example)

yaml.safe_load parses the workflow; the check job and the trigger are
untouched.

The manifest sync step substituted the PR title into the commit message, so a title containing a command substitution ran in a pull_request_target job. Read it from env.
Co-Authored-By: Shengcun <business@rs-systems-web.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant