1
1
# ###############################################################################
2
2
# File: .github/workflows/unicode_warn.yml
3
- # Version: 0.1
3
+ # Version: 0.2
4
4
# Purpose: Detects Unicode in PRs and comments the results of findings in PR
5
- # * https://tech.michaelaltfield.net/bidi-unicode-github-defense/
6
5
# Authors: Michael Altfield <michael@michaelaltfield.net>
7
6
# Created: 2021-11-20
8
- # Updated: 2021-11-20
7
+ # Updated: 2024-08-07
9
8
# ###############################################################################
9
+ # in main branch
10
10
name : malicious_sanity_checks
11
11
12
12
# execute this workflow automatically on all PRs
13
- on : [pull_request]
13
+ on :
14
+ pull_request_target :
15
+ types : [opened, edited, synchronize, reopened, unlocked]
14
16
15
17
jobs :
16
18
17
19
unicode_warn :
18
-
20
+
19
21
runs-on : ubuntu-latest
20
22
container : debian:bullseye-slim
21
-
23
+
24
+ permissions :
25
+ issues : write
26
+ pull-requests : write
27
+
22
28
steps :
23
29
24
30
- name : Prereqs
31
+ continue-on-error : true
25
32
env :
26
33
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
27
34
run : |
@@ -34,12 +41,31 @@ jobs:
34
41
id : unicode_diff
35
42
run : |
36
43
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
+
37
49
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
+
38
57
unicode_diff=`echo -n "${diff}" | grep -oP "[^\x00-\x7F]*"`
39
58
unicode_grep_exit_code=$?
40
59
echo "${unicode_diff}"
41
60
42
61
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
+
43
69
echo "${unicode_diff_hexdump}"
44
70
45
71
# did we select any unicode characters?
@@ -75,3 +101,14 @@ jobs:
75
101
repo: context.repo.repo,
76
102
body: "${{ env.UNICODE_HUMAN_RESULT }}"
77
103
})
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