Skip to content

SNOW-2069227 : Update jira_close.yml #2452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions .github/workflows/jira_close.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,36 @@
close-issue:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
repository: snowflakedb/gh-actions
ref: jira_v1
token: ${{ secrets.SNOWFLAKE_GITHUB_TOKEN }} # stored in GitHub secrets
path: .
- name: Jira login
uses: atlassian/gajira-login@master
env:
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
- name: Extract issue from title
id: extract
env:
TITLE: "${{ github.event.issue.title }}"
run: |
jira=$(echo -n $TITLE | awk '{print $1}' | sed -e 's/://')
echo ::set-output name=jira::$jira
- name: Close issue
uses: ./jira/gajira-close

- name: Close Jira Issue
if: startsWith(steps.extract.outputs.jira, 'SNOW-')
with:
issue: "${{ steps.extract.outputs.jira }}"
run: |
ISSUE_KEY="${{ steps.extract.outputs.jira }}"

Check failure

Code scanning / CodeQL

Code injection Critical

Potential code injection in
${ steps.extract.outputs.jira }
, which may be controlled by an external user (
issues
).

Copilot Autofix

AI 14 days ago

To fix the code injection vulnerability, we should avoid interpolating untrusted input directly into shell commands using ${{ ... }} or shell variable expansion. Instead, we should pass the untrusted value as an environment variable and reference it using the shell's native variable syntax (e.g., $ISSUE_KEY), ensuring it is properly quoted. In this workflow, we should set ISSUE_KEY as an environment variable in the step, and then use "$ISSUE_KEY" in the shell script. This prevents shell injection because the shell will not interpret special characters inside the variable value. The change should be made in the "Close Jira Issue" step, moving the assignment of ISSUE_KEY from the script to the env: block, and referencing it as "$ISSUE_KEY" in the script.


Suggested changeset 1
.github/workflows/jira_close.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/jira_close.yml b/.github/workflows/jira_close.yml
--- a/.github/workflows/jira_close.yml
+++ b/.github/workflows/jira_close.yml
@@ -20,6 +20,6 @@
         if: startsWith(steps.extract.outputs.jira, 'SNOW-')
+        env:
+          ISSUE_KEY: ${{ steps.extract.outputs.jira }}
+          JIRA_API_URL: ${{ secrets.JIRA_BASE_URL }}/rest/api/2/issue/${{ steps.extract.outputs.jira }}/transitions
         run: |
-          ISSUE_KEY="${{ steps.extract.outputs.jira }}"
-          JIRA_API_URL="${{ secrets.JIRA_BASE_URL }}/rest/api/2/issue/${ISSUE_KEY}/transitions"
-
           curl -X POST \
EOF
@@ -20,6 +20,6 @@
if: startsWith(steps.extract.outputs.jira, 'SNOW-')
env:
ISSUE_KEY: ${{ steps.extract.outputs.jira }}
JIRA_API_URL: ${{ secrets.JIRA_BASE_URL }}/rest/api/2/issue/${{ steps.extract.outputs.jira }}/transitions
run: |
ISSUE_KEY="${{ steps.extract.outputs.jira }}"
JIRA_API_URL="${{ secrets.JIRA_BASE_URL }}/rest/api/2/issue/${ISSUE_KEY}/transitions"

curl -X POST \
Copilot is powered by AI and may make mistakes. Always verify output.
JIRA_API_URL="${{ secrets.JIRA_BASE_URL }}/rest/api/2/issue/${ISSUE_KEY}/transitions"

curl -X POST \
--url "$JIRA_API_URL" \
--user "${{ secrets.JIRA_USER_EMAIL }}:${{ secrets.JIRA_API_TOKEN }}" \
--header "Content-Type: application/json" \
--data "{
\"update\": {
\"comment\": [
{ \"add\": { \"body\": \"Closed on GitHub\" } }
]
},
\"fields\": {
\"customfield_12860\": { \"id\": \"11506\" },
\"customfield_10800\": { \"id\": \"-1\" },
\"customfield_12500\": { \"id\": \"11302\" },
\"customfield_12400\": { \"id\": \"-1\" },
\"resolution\": { \"name\": \"Done\" }
},
\"transition\": { \"id\": \"71\" }
}"
Loading