Commit f564947c20

f564947c20efbceb24fc280a6e5ce9e5f2621fb8

parent: f1b012efb2

Unsigned

Alicia Sykes <alicia@omg.lol> · 2026-03-07 16:54 UTC

Implements the anti-spam check

Layout: unified · split

.github/workflows/pr-check.yml +2
@@ -32,6 +32,7 @@ jobs:
32 PR_TITLE: ${{ github.event.pull_request.title }} 32 PR_TITLE: ${{ github.event.pull_request.title }}
33 PR_BODY: ${{ github.event.pull_request.body }} 33 PR_BODY: ${{ github.event.pull_request.body }}
34 PR_DRAFT: ${{ github.event.pull_request.draft }} 34 PR_DRAFT: ${{ github.event.pull_request.draft }}
35 BASE_REF: ${{ github.event.pull_request.base.sha }}
35 README_FAILED: ${{ steps.readme.outcome == 'failure' && 'true' || 'false' }} 36 README_FAILED: ${{ steps.readme.outcome == 'failure' && 'true' || 'false' }}
36 run: python lib/checks/check-pr-meta.py 37 run: python lib/checks/check-pr-meta.py
37 - name: Upload findings 38 - name: Upload findings
@@ -117,6 +118,7 @@ jobs:
117 - name: Check project health 118 - name: Check project health
118 env: 119 env:
119 PR_USER: ${{ github.event.pull_request.user.login }} 120 PR_USER: ${{ github.event.pull_request.user.login }}
121 PR_BODY: ${{ github.event.pull_request.body }}
120 GITHUB_TOKEN: ${{ github.token }} 122 GITHUB_TOKEN: ${{ github.token }}
121 run: python lib/checks/check-project.py 123 run: python lib/checks/check-project.py
122 - name: Upload findings 124 - name: Upload findings
lib/checks/check-pr-meta.py +33
@@ -3,6 +3,7 @@
3import json 3import json
4import os 4import os
5import re 5import re
6import subprocess
6import sys 7import sys
7 8
8FINDINGS_PATH = "/tmp/findings-compliance.json" 9FINDINGS_PATH = "/tmp/findings-compliance.json"
@@ -32,6 +33,15 @@ README_MSG = (
32 " content in `awesome-privacy.yml`, and so your changes will be overridden!" 33 " content in `awesome-privacy.yml`, and so your changes will be overridden!"
33 " Instead, only modify the YAML file, and be sure to follow our Contributing Guidelines." 34 " Instead, only modify the YAML file, and be sure to follow our Contributing Guidelines."
34) 35)
36BOT_MSG = (
37 "Submissions are only accepted from humans."
38 " This PR appears to have been authored by a bot or AI assistant."
39)
40
41_BOT_AUTHOR_RE = re.compile(
42 r"(?:noreply@anthropic\.com|devin-ai-integration|copilot-swe-agent|noreply@cursor\.com)",
43 re.IGNORECASE,
44)
35 45
36 46
37def extract_section(body, header): 47def extract_section(body, header):
@@ -83,6 +93,24 @@ def check_checkboxes(body):
83 return None 93 return None
84 94
85 95
96def check_bot_coauthors(base_ref):
97 """Return a finding if any commit in the PR has a bot author or co-author."""
98 if not base_ref:
99 return None
100 try:
101 result = subprocess.run(
102 ["git", "log", f"{base_ref}..HEAD", "--format=%aN <%aE>%n%B"],
103 capture_output=True, text=True, timeout=30,
104 )
105 if result.returncode != 0:
106 return None
107 if _BOT_AUTHOR_RE.search(result.stdout):
108 return BOT_MSG
109 except Exception:
110 pass
111 return None
112
113
86def check_readme(readme_failed): 114def check_readme(readme_failed):
87 """Return a finding if the README check reported a failure.""" 115 """Return a finding if the README check reported a failure."""
88 if readme_failed == "true": 116 if readme_failed == "true":
@@ -104,6 +132,11 @@ def main():
104 body = os.environ.get("PR_BODY", "") 132 body = os.environ.get("PR_BODY", "")
105 draft = os.environ.get("PR_DRAFT", "false") 133 draft = os.environ.get("PR_DRAFT", "false")
106 readme_failed = os.environ.get("README_FAILED", "false") 134 readme_failed = os.environ.get("README_FAILED", "false")
135 base_ref = os.environ.get("BASE_REF", "")
136
137 finding = check_bot_coauthors(base_ref)
138 if finding:
139 findings.append(finding)
107 140
108 finding = check_title(title) 141 finding = check_title(title)
109 if finding: 142 if finding:
lib/checks/check-project.py +83 −13
@@ -2,8 +2,9 @@
2 2
3import json 3import json
4import os 4import os
5import re
5import sys 6import sys
6from datetime import datetime, timezone 7from datetime import datetime, timedelta, timezone
7 8
8import requests 9import requests
9import yaml 10import yaml
@@ -18,11 +19,14 @@ USER_AGENT = "awesome-privacy-ci/1.0"
18MIN_STARS = 100 19MIN_STARS = 100
19INACTIVE_DAYS = 90 20INACTIVE_DAYS = 90
20MIN_AGE_DAYS = 120 21MIN_AGE_DAYS = 120
21AI_COMMIT_THRESHOLD = 5 22AI_COMMIT_RATIO = 0.2
22AI_BOT_AUTHORS = [ 23AI_BOT_AUTHORS = [
23 "noreply@anthropic.com", 24 "noreply@anthropic.com",
24 "devin-ai-integration[bot]", 25 "devin-ai-integration[bot]",
26 "copilot-swe-agent.github.com",
27 "noreply@cursor.com",
25] 28]
29SPAM_PR_THRESHOLD = 5
26 30
27LINK_MSG = ( 31LINK_MSG = (
28 "Our automated checks were unable to verify the link(s) you included" 32 "Our automated checks were unable to verify the link(s) you included"
@@ -33,7 +37,7 @@ AUTHOR_MSG = (
33 " have clearly disclosed this in your PR body for transparency" 37 " have clearly disclosed this in your PR body for transparency"
34) 38)
35STARS_MSG = ( 39STARS_MSG = (
36 "It looks like your submission is adding a quite small project." 40 "It looks like your submission is quite a small project without a lot of users yet."
37 " In some circumstances we may ask you to resubmit this once the project" 41 " In some circumstances we may ask you to resubmit this once the project"
38 " is more mature and has a proven track record of good practices and maintenance." 42 " is more mature and has a proven track record of good practices and maintenance."
39) 43)
@@ -64,6 +68,10 @@ SECURITY_MSG = (
64 "This project has open security vulnerabilities (critical or high severity)" 68 "This project has open security vulnerabilities (critical or high severity)"
65 " flagged by GitHub Dependabot. Please verify these have been addressed" 69 " flagged by GitHub Dependabot. Please verify these have been addressed"
66) 70)
71SPAM_MSG = (
72 "This user has opened up a large number of PRs to other awesome-* repos"
73 " in the past 24 hours, and appears to be spamming"
74)
67 75
68 76
69def load_diff(path): 77def load_diff(path):
@@ -183,6 +191,21 @@ def check_links(diff, head):
183 return None 191 return None
184 192
185 193
194def _commit_has_bot(commit, bot_set):
195 """Check if a commit was authored or co-authored by a known AI bot."""
196 author = commit.get("commit", {}).get("author", {})
197 email = (author.get("email") or "").lower()
198 name = (author.get("name") or "").lower()
199 if email in bot_set or name in bot_set:
200 return True
201 message = (commit.get("commit", {}).get("message") or "").lower()
202 for line in message.splitlines():
203 if line.strip().startswith("co-authored-by:"):
204 if any(bot in line for bot in bot_set):
205 return True
206 return False
207
208
186def check_ai_commits(owner, repo, token): 209def check_ai_commits(owner, repo, token):
187 """Return AI_CODE_MSG if recent commits contain significant AI bot activity.""" 210 """Return AI_CODE_MSG if recent commits contain significant AI bot activity."""
188 try: 211 try:
@@ -195,15 +218,12 @@ def check_ai_commits(owner, repo, token):
195 ) 218 )
196 if resp.status_code != 200: 219 if resp.status_code != 200:
197 return None 220 return None
221 commits = resp.json()
222 if not commits:
223 return None
198 bot_set = {a.lower() for a in AI_BOT_AUTHORS} 224 bot_set = {a.lower() for a in AI_BOT_AUTHORS}
199 count = 0 225 count = sum(1 for c in commits if _commit_has_bot(c, bot_set))
200 for commit in resp.json(): 226 if count / len(commits) >= AI_COMMIT_RATIO:
201 author = commit.get("commit", {}).get("author", {})
202 email = (author.get("email") or "").lower()
203 name = (author.get("name") or "").lower()
204 if email in bot_set or name in bot_set:
205 count += 1
206 if count >= AI_COMMIT_THRESHOLD:
207 return AI_CODE_MSG 227 return AI_CODE_MSG
208 except Exception: 228 except Exception:
209 pass 229 pass
@@ -228,7 +248,51 @@ def check_security_alerts(owner, repo, token):
228 return None 248 return None
229 249
230 250
231def check_repo_signals(diff, pr_user, token): 251def check_spam_prs(pr_user, token):
252 """Return SPAM_MSG if the user has opened many PRs to other awesome-* repos recently."""
253 if not pr_user or not token:
254 return None
255 try:
256 since = (datetime.now(timezone.utc) - timedelta(days=1)).strftime("%Y-%m-%d")
257 headers = {"Accept": "application/vnd.github.v3+json", "User-Agent": USER_AGENT}
258 headers["Authorization"] = f"token {token}"
259 resp = requests.get(
260 "https://api.github.com/search/issues",
261 headers=headers, timeout=TIMEOUT,
262 params={"q": f"type:pr author:{pr_user} created:>={since}"},
263 )
264 if resp.status_code != 200:
265 return None
266 items = resp.json().get("items", [])
267 this_repo = os.environ.get("GITHUB_REPOSITORY", "Lissy93/awesome-privacy").lower()
268 count = 0
269 for item in items:
270 repo_url = item.get("repository_url", "")
271 # repository_url looks like https://api.github.com/repos/owner/repo-name
272 repo_full = "/".join(repo_url.rstrip("/").split("/")[-2:]).lower()
273 repo_name = repo_url.rstrip("/").split("/")[-1].lower()
274 if repo_name.startswith("awesome-") and repo_full != this_repo:
275 count += 1
276 if count >= SPAM_PR_THRESHOLD:
277 return SPAM_MSG
278 except Exception:
279 pass
280 return None
281
282
283_DISCLOSURE_RE = re.compile(
284 r"i am the author|i'm the author|my project|i created|i develop"
285 r"|i maintain|i built|my own project|i made|author of|maintainer of",
286 re.IGNORECASE,
287)
288
289
290def _pr_discloses_authorship(pr_body):
291 """Return True if the PR body already discloses the submitter is the author."""
292 return bool(pr_body and _DISCLOSURE_RE.search(pr_body))
293
294
295def check_repo_signals(diff, pr_user, token, pr_body=""):
232 """Check GitHub repo author match, stars, and activity for added services.""" 296 """Check GitHub repo author match, stars, and activity for added services."""
233 findings = [] 297 findings = []
234 if not token: 298 if not token:
@@ -252,6 +316,7 @@ def check_repo_signals(diff, pr_user, token):
252 and repo_owner.get("type") == "User" 316 and repo_owner.get("type") == "User"
253 and repo_owner.get("login", "").lower() == pr_user.lower() 317 and repo_owner.get("login", "").lower() == pr_user.lower()
254 and AUTHOR_MSG not in findings 318 and AUTHOR_MSG not in findings
319 and not _pr_discloses_authorship(pr_body)
255 ): 320 ):
256 findings.append(AUTHOR_MSG) 321 findings.append(AUTHOR_MSG)
257 322
@@ -316,8 +381,13 @@ def main():
316 findings.append(finding) 381 findings.append(finding)
317 382
318 pr_user = os.environ.get("PR_USER", "") 383 pr_user = os.environ.get("PR_USER", "")
384 pr_body = os.environ.get("PR_BODY", "")
319 token = os.environ.get("GITHUB_TOKEN", "") 385 token = os.environ.get("GITHUB_TOKEN", "")
320 findings.extend(check_repo_signals(diff, pr_user, token)) 386 findings.extend(check_repo_signals(diff, pr_user, token, pr_body))
387
388 finding = check_spam_prs(pr_user, token)
389 if finding:
390 findings.append(finding)
321 except Exception: 391 except Exception:
322 pass 392 pass
323 393