Skip to content

security: ci: read the issue body from the environment - #1

Open
Shengcun-Scanner wants to merge 1 commit into
deepakrummy:mainfrom
Shengcun-Scanner:shengcun/cicd-issue-body-injection
Open

Shengcun-Scanner wants to merge 1 commit into
deepakrummy:mainfrom
Shengcun-Scanner:shengcun/cicd-issue-body-injection

Conversation

@Shengcun-Scanner

Copy link
Copy Markdown

greet.yml labels new issues by looking for campaign tags in the body, and it feeds
the body to grep through a here-string:

- name: Add label if issue body contains "GSSoC24"
  run: |
    if grep -qE "GSSoC24" <<< "${{ github.event.issue.body }}"; then

The same shape repeats for GSSoC23, hacktoberfest and IWOC2024. The runner
substitutes the text before bash parses the step, so a body containing " ends the
here-string argument and the rest of the body is executed inside the workflow runner.
The personal access token is in with: on the later github-script steps rather than
in this step's environment, so the shell is not how it is reached; the runner is.

Fix

Set the body once at job level and use it as a variable:

jobs:
  comment_and_label:
    runs-on: ubuntu-latest
    env:
      ISSUE_BODY: ${{ github.event.issue.body }}
- name: Add label if issue body contains "GSSoC24"
  run: |
    if grep -qE "GSSoC24" <<< "$ISSUE_BODY"; then

The four grep tests, the set-output results and the labelling steps are otherwise
untouched.

Verification

$ body='x"; touch /tmp/pwned; echo "GSSoC24'
$ printf 'if grep -qE "GSSoC24" <<< "%s"; then :; fi\n' "$body" > old.sh
$ bash old.sh && ls /tmp/pwned
/tmp/pwned
$ ISSUE_BODY="$body" bash -c 'if grep -qE "GSSoC24" <<< "$ISSUE_BODY"; then :; fi'
$ ls /tmp/pwned
ls: cannot access '/tmp/pwned': No such file or directory

yaml.safe_load parses the workflow; the trigger, the comment step and both
github-script steps are unchanged.

The labelling steps put the issue body inside a here-string, so a body containing a quote could run commands in a job that holds a personal access token. Read the body from env instead.

Co-Authored-By: Shengcun <business@rs-systems-web.com>

This branch has not been deployed

No deployments
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