Skip to content

Commit 16634e6

Browse files
authored
Merge pull request #18540 from JarLob/bash
Actions: Improve bash support
2 parents 78d0c5c + 9521467 commit 16634e6

File tree

6 files changed

+100
-10
lines changed

6 files changed

+100
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: fix
3+
---
4+
* Improved `untrustedGhCommandDataModel` regex for `gh pr view` and Bash taint analysis in GitHub Actions.

actions/ql/lib/codeql/actions/Bash.qll

+13
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,19 @@ module Bash {
695695
not varMatchesRegexTest(script, var2, alphaNumericRegex())
696696
)
697697
or
698+
exists(string var2, string value2, string var3, string value3 |
699+
// VAR2=$(cmd)
700+
// VAR3=$VAR2
701+
// echo "FIELD=${VAR3:-default}" >> $GITHUB_ENV (field, file_write_value)
702+
containsCmdSubstitution(value2, cmd) and
703+
script.getAnAssignment(var2, value2) and
704+
containsParameterExpansion(value3, var2, _, _) and
705+
script.getAnAssignment(var3, value3) and
706+
containsParameterExpansion(expr, var3, _, _) and
707+
not varMatchesRegexTest(script, var2, alphaNumericRegex()) and
708+
not varMatchesRegexTest(script, var3, alphaNumericRegex())
709+
)
710+
or
698711
// var reaches the file write directly
699712
// echo "FIELD=$(cmd)" >> $GITHUB_ENV (field, file_write_value)
700713
containsCmdSubstitution(expr, cmd)

actions/ql/lib/ext/config/untrusted_gh_command.yml

+12-9
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,29 @@ extensions:
77
# PULL REQUESTS
88
#
99
# HEAD_REF=$(gh pr view "${{ github.event.issue.number }}" --json headRefName -q '.headRefName')
10-
- ["gh\\s+pr\\b.*\\bview\\b.*\\.headRefName.*", "branch,oneline"]
10+
- ["gh\\s+pr\\b.*\\bview\\b.*\\bheadRefName\\b", "branch,oneline"]
1111
# TITLE=$(gh pr view $PR_NUMBER --json title --jq .title)
12-
- ["gh\\s+pr\\b.*\\bview\\b.*\\.title.*", "title,oneline"]
12+
# TITLE=$(gh pr view $PR_NUMBER --json "title")
13+
- ["gh\\s+pr\\b.*\\bview\\b.*\\btitle\\b", "title,oneline"]
1314
# BODY=$(gh pr view $PR_NUMBER --json body --jq .body)
14-
- ["gh\\s+pr\\b.*\\bview\\b.*\\.body.*", "text,multiline"]
15+
- ["gh\\s+pr\\b.*\\bview\\b.*\\bbody\\b", "text,multiline"]
1516
# COMMENTS="$(gh pr view --repo ${{ github.repository }} "$PR_NUMBER" --json "body,comments" -q '.body, .comments[].body')"
16-
- ["gh\\s+pr\\b.*\\bview\\b.*\\.comments.*", "text,multiline"]
17+
- ["gh\\s+pr\\b.*\\bview\\b.*\\bcomments\\b", "text,multiline"]
1718
# CHANGED_FILES="$(gh pr view --repo ${{ github.repository }} ${{ needs.check-comment.outputs.pull_number }} --json files --jq '.files.[].path')"
18-
- ["gh\\s+pr\\b.*\\bview\\b.*\\.files.*", "filename,multiline"]
19+
- ["gh\\s+pr\\b.*\\bview\\b.*\\bfiles\\b", "filename,multiline"]
1920
# AUTHOR=$(gh pr view ${ORI_PR} -R ${REPO} --json author -q '.author.login')
20-
- ["gh\\s+pr\\b.*\\bview\\b.*\\.author.*", "username,oneline"]
21+
- ["gh\\s+pr\\b.*\\bview\\b.*\\bauthor\\b", "username,oneline"]
2122
#
2223
# ISSUES
2324
#
2425
# TITLE=$(gh issue view "$ISSUE_NUMBER" --json title --jq '.title')
25-
- ["gh\\s+issue\\b.*\\bview\\b.*\\.title.*", "title,oneline"]
26+
# TITLE=$(gh issue view "$ISSUE_NUMBER" --json title,body)
27+
# TITLE=$(gh issue view "$ISSUE_NUMBER" --json "title,body")
28+
- ["gh\\s+issue\\b.*\\bview\\b.*\\btitle\\b", "title,oneline"]
2629
# BODY=$(gh issue view -R ${GITHUB_REPOSITORY} ${ORIGINAL_ISSUE_NUMBER} --json title,body,assignees --jq .body)
27-
- ["gh\\s+issue\\b.*\\bview\\b.*\\.body.*", "text,multiline"]
30+
- ["gh\\s+issue\\b.*\\bview\\b.*\\bbody\\b", "text,multiline"]
2831
# COMMENTS=$(gh issue view "$ISSUE_NUMBER" --json comments --jq '.comments[].body')
29-
- ["gh\\s+issue\\b.*\\bview\\b.*\\.comments.*", "text,multiline"]
32+
- ["gh\\s+issue\\b.*\\bview\\b.*\\bcomments\\b", "text,multiline"]
3033
#
3134
# API
3235
#

actions/ql/test/query-tests/Security/CWE-094/.github/workflows/test19.yml

+21-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,27 @@ jobs:
106106
COMMENTS=$(gh api /repos/test/test/pulls/${PR_NUMBER}/comments --jq '.[].body')
107107
echo "comments=$COMMENTS" >> "$GITHUB_OUTPUT"
108108
- run: echo "${{ steps.comments.outputs.comments}}"
109-
109+
pulls3:
110+
runs-on: ubuntu-latest
111+
steps:
112+
- id: title1
113+
run: |
114+
DETAILS=$(gh pr view $PR_NUMBER --json "title,author,headRefName")
115+
TITLE=$(echo $DETAILS | jq -r '.title')
116+
echo "title=$TITLE" >> "$GITHUB_OUTPUT"
117+
- run: echo "${{ steps.title1.outputs.title}}"
118+
- id: title2
119+
run: |
120+
TITLE=$(gh pr view $PR_NUMBER --json "title,author,headRefName")
121+
TITLE=$(echo $TITLE | jq -r '.title')
122+
echo "title=$TITLE" >> "$GITHUB_OUTPUT"
123+
- run: echo "${{ steps.title2.outputs.title}}"
124+
- id: title3
125+
run: |
126+
TITLE=$(gh issue view "$ISSUE_NUMBER" --json title,author)
127+
TITLE=$(echo $TITLE | jq -r '.title')
128+
echo "title=$TITLE" >> "$GITHUB_OUTPUT"
129+
- run: echo "${{ steps.title3.outputs.title}}"
110130

111131

112132

0 commit comments

Comments
 (0)