Skip to content

Commit

Permalink
fixes to CI workflow to detect malicious unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
maltfield committed Aug 8, 2024
1 parent eeb21ad commit cd22f67
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/unicode_warn.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
################################################################################
# File: .github/workflows/unicode_warn.yml
# Version: 0.3
# Version: 0.4
# Purpose: Detects Unicode in PRs and comments the results of findings in PR
# Authors: Michael Altfield <michael@michaelaltfield.net>
# Created: 2021-11-20
Expand All @@ -26,6 +26,11 @@ jobs:
pull-requests: write

steps:

- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: echo "$GITHUB_CONTEXT"

- name: Prereqs
env:
Expand All @@ -45,11 +50,15 @@ jobs:
git config --global --add safe.directory "$(pwd)"
git branch -a
git log
git checkout ${{ github.event.pull_request.head.ref }}
git branch -a
git log
diff=`git diff --unified=0 ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep -E "^[+]" | grep -Ev '^(--- a/|\+\+\+ b/)'`
if [ $? -ne 0 ]; then
# there was an error in the diff
human_result="WARNING: git diff failed!"
echo "UNICODE_HUMAN_RESULT=${human_result}" >> $GITHUB_ENV
echo "${human_result}"
exit 1
fi
Expand All @@ -62,6 +71,7 @@ jobs:
if [ $? -ne 0 ]; then
# there was an error in the hexdump
human_result="WARNING: hexdump failed!"
echo "UNICODE_HUMAN_RESULT=${human_result}" >> $GITHUB_ENV
echo "${human_result}"
exit 1
fi
Expand Down Expand Up @@ -106,7 +116,7 @@ jobs:
- name: Exit with or without error
run: |
if [[ "${{ env.UNICODE_HUMAN_RESULT }}" | grep -i "WARNING" ]]; then
if [[ "${{ env.UNICODE_HUMAN_RESULT }}" | grep -Ei "ERROR|WARNING" ]]; then
exit 1
else
exit 0
Expand Down

0 comments on commit cd22f67

Please sign in to comment.