Place untrusted data from the git commit metadata in environment variables.
This prevents bash from executing strings in the commit metadata as code when reporting build errors. PiperOrigin-RevId: 580155315 Change-Id: I4046eabd76eba14297fffe4e2fced59259d80f21
This commit is contained in:
committed by
Copybara-Service
parent
1881c2d881
commit
7207b60b5a
+29
-17
@@ -252,20 +252,32 @@ jobs:
|
||||
- name: Notify team chat
|
||||
shell: bash
|
||||
env:
|
||||
GCHAT_API: ${{ secrets.GCHAT_API }}
|
||||
JOB_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/\
|
||||
${{ github.run_id }}"
|
||||
if: ${{ failure() && github.event_name == 'push' && env.GCHAT_API != '' }}
|
||||
run: >
|
||||
curl
|
||||
"$GCHAT_API&threadKey=$GITHUB_SHA&messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD"
|
||||
-X POST
|
||||
-H "Content-Type: application/json"
|
||||
-d "{
|
||||
'text': '<$JOB_URL|*FAILURE*>:
|
||||
job \`${{ matrix.os }}${{ matrix.additional_label }}\`
|
||||
commit \`$(echo $GITHUB_SHA | head -c6)\`\n
|
||||
\`\`\`Author: ${{ github.event.head_commit.author.name }}
|
||||
<${{ github.event.head_commit.author.email }}>
|
||||
\n\n${{ github.event.head_commit.message }}\`\`\`
|
||||
'}"
|
||||
GCHAT_API_URL: ${{ secrets.GCHAT_API }}
|
||||
JOB_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
|
||||
CHATMSG_AUTHOR_NAME: ${{ github.event.head_commit.author.name }}
|
||||
CHATMSG_AUTHOR_EMAIL: ${{ github.event.head_commit.author.email }}
|
||||
CHATMSG_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
|
||||
CHATMSG_JOB_ID: ${{ matrix.os }}${{ matrix.additional_label }}
|
||||
if: ${{ failure() && github.event_name == 'push' && env.GCHAT_API_URL != '' }}
|
||||
run: |
|
||||
CHATMSG="$(cat <<-'EOF' | python3
|
||||
import json
|
||||
import os
|
||||
env = lambda x: os.getenv(x, '')
|
||||
data = dict(
|
||||
result=env('JOB_URL'),
|
||||
job=env('CHATMSG_JOB_ID'),
|
||||
commit=env('GITHUB_SHA')[:6],
|
||||
name=env('CHATMSG_AUTHOR_NAME').replace('```', ''),
|
||||
email=env('CHATMSG_AUTHOR_EMAIL'),
|
||||
msg=env('CHATMSG_COMMIT_MESSAGE').replace('```', '')
|
||||
)
|
||||
text = '<{result}|*FAILURE*>: job `{job}` commit `{commit}`\n```Author: {name}<{email}>\n\n{msg}```'.format(**data)
|
||||
print(json.dumps({'text' : text}))
|
||||
EOF
|
||||
)" &&
|
||||
|
||||
curl "$GCHAT_API_URL&threadKey=$GITHUB_SHA&messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD" \
|
||||
-X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-raw "${CHATMSG}"
|
||||
|
||||
Reference in New Issue
Block a user