Skip to content

Commit ece61e3

Browse files
committed
update check for malicious unicode
* maltfield/detect-malicious-unicode#3 * #90 (comment)
1 parent 924ca98 commit ece61e3

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

.github/workflows/unicode_warn.yml

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
################################################################################
22
# File: .github/workflows/unicode_warn.yml
3-
# Version: 0.1
3+
# Version: 0.2
44
# Purpose: Detects Unicode in PRs and comments the results of findings in PR
5-
# * https://tech.michaelaltfield.net/bidi-unicode-github-defense/
65
# Authors: Michael Altfield <michael@michaelaltfield.net>
76
# Created: 2021-11-20
8-
# Updated: 2021-11-20
7+
# Updated: 2024-08-07
98
################################################################################
9+
# in main branch
1010
name: malicious_sanity_checks
1111

1212
# execute this workflow automatically on all PRs
13-
on: [pull_request]
13+
on:
14+
pull_request_target:
15+
types: [opened, edited, synchronize, reopened, unlocked]
1416

1517
jobs:
1618

1719
unicode_warn:
18-
20+
1921
runs-on: ubuntu-latest
2022
container: debian:bullseye-slim
21-
23+
24+
permissions:
25+
issues: write
26+
pull-requests: write
27+
2228
steps:
2329

2430
- name: Prereqs
31+
continue-on-error: true
2532
env:
2633
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2734
run: |
@@ -34,12 +41,31 @@ jobs:
3441
id: unicode_diff
3542
run: |
3643
set -x
44+
git config --global --add safe.directory .
45+
git config --global --add safe.directory "$(pwd)"
46+
git branch -a
47+
git log
48+
3749
diff=`git diff --unified=0 ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep -E "^[+]" | grep -Ev '^(--- a/|\+\+\+ b/)'`
50+
if [ $? -ne 0 ]; then
51+
# there was an error in the diff
52+
human_result="WARNING: git diff failed!"
53+
echo "${human_result}"
54+
exit 1
55+
fi
56+
3857
unicode_diff=`echo -n "${diff}" | grep -oP "[^\x00-\x7F]*"`
3958
unicode_grep_exit_code=$?
4059
echo "${unicode_diff}"
4160
4261
unicode_diff_hexdump=`echo -n "${unicode_diff}" | hd`
62+
if [ $? -ne 0 ]; then
63+
# there was an error in the hexdump
64+
human_result="WARNING: hexdump failed!"
65+
echo "${human_result}"
66+
exit 1
67+
fi
68+
4369
echo "${unicode_diff_hexdump}"
4470

4571
# did we select any unicode characters?
@@ -75,3 +101,14 @@ jobs:
75101
repo: context.repo.repo,
76102
body: "${{ env.UNICODE_HUMAN_RESULT }}"
77103
})
104+
105+
# Exit with or without error
106+
- name: Exit with or without error
107+
run: |
108+
109+
if [[ "${{ env.UNICODE_HUMAN_RESULT }}" | grep -i "WARNING" ]]; then
110+
exit 1
111+
else
112+
exit 0
113+
114+
shell: bash {0}

0 commit comments

Comments
 (0)