-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
73 lines (69 loc) · 2.4 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
name: Sanitize comment
description: GitHub Action to sanitize suspicious comments
branding:
icon: crosshair
color: red
runs:
using: composite
steps:
- uses: actions/github-script@v7
with:
script: |
const preamble = "> [!CAUTION]\n> This comment may contain links to malicious content. **DO NOT** follow any links below\n\n";
const replacer = (url) => url.replace('.', '(dot)');
const patterns = [
/(app\.|www\.)?mediafire\.com/,
/(www\.)?(onedrive|1drv)\.(com|ms)/,
/(www\.)?box\.com/,
/(www\.)?citrixsharefile\.com/,
/(www\.)?dropbox\.com/,
/(www\.)?hightail\.com/,
/(www\.)?icloud\.com/,
/(www\.)?icloud\.com/,
/(www\.)?mega\.((co\.)?nz|io)/,
/(www\.)?opentext\.com/,
/(www\.)?sharefile\.com/,
/(www\.)?sugarsync\.com/,
/(www\.)?tresorit\.com/,
/bit\.ly/,
/bl\.ink/,
/buff\.ly/,
/cdn\.discordapp\.com/,
/clck\.ru/,
/cutt\.ly/,
/drive\.google\.com/,
/gofile\.io/,
/goo\.gl/,
/is\.gd/,
/lnkd\.in/,
/media\.discordapp\.net/,
/ow\.ly/,
/qr\.ae/,
/rb\.gy/,
/rebrand\.ly/,
/shorte\.st/,
/shorturl\.at/,
/soo\.gd/,
/t\.co/,
/t2mio/,
/tinyurl\.com/,
/tr\.im/,
/v\.gd/,
];
const comment = context.payload.comment;
const { owner, repo } = context.repo;
const comment_id = comment.id;
console.log(`Repository owner: ${owner}`);
console.log(`Repository name: ${repo}`);
console.log(`Comment body: ${comment.body}`);
const pattern = new RegExp(`(https?://|[\\s(<])(${patterns.map(x => x.source).join('|')})/`, 'g');
if (pattern.test(comment.body)) {
let body = comment.body.replace(pattern, replacer);
if (!comment.body.trimStart().startsWith(preamble.trim())) {
body = preamble + body;
}
console.log(`Updated comment body: ${body}`);
await github.rest.issues.updateComment({ owner, repo, comment_id, body });
} else {
console.log('No suspicious links found.');
}