Commit 0d22adce5c
Unsigned
Layout: unified · split
.github/CONTRIBUTING.md +1
| @@ -304,6 +304,7 @@ Below is the full list of checks - it's basically the same as what is listed in | |||
| 304 | - 🟡 **Has license** - Repo should include a license | 304 | - 🟡 **Has license** - Repo should include a license |
| 305 | - 🟡 **Not archived** - Repo must not be archived | 305 | - 🟡 **Not archived** - Repo must not be archived |
| 306 | - 🟡 **No security alerts** - No open critical/high Dependabot alerts | 306 | - 🟡 **No security alerts** - No open critical/high Dependabot alerts |
| 307 | - 🟡 **Security policy** - Repo should have a security policy (SECURITY.md) and/or private vulnerability reporting enabled | ||
| 307 | - 🟡 **Minimum stars** - Repo should have ≥100 stars | 308 | - 🟡 **Minimum stars** - Repo should have ≥100 stars |
| 308 | - 🟡 **Bus factor** - Flags if ≥96% of commits come from a single contributor (bots and AI excluded) | 309 | - 🟡 **Bus factor** - Flags if ≥96% of commits come from a single contributor (bots and AI excluded) |
| 309 | - 🟡 **Spam detection** - Flags if the author opened ≥3 PRs to other awesome-* repos, or PRs across ≥7 distinct repos, in the last 2 days | 310 | - 🟡 **Spam detection** - Flags if the author opened ≥3 PRs to other awesome-* repos, or PRs across ≥7 distinct repos, in the last 2 days |
lib/checks/check-project.py +16
| @@ -100,6 +100,10 @@ REPO_404_MSG = ( | |||
| 100 | BUS_FACTOR_MSG = ( | 100 | BUS_FACTOR_MSG = ( |
| 101 | "This repository has a low bus factor, as maintained by a single contributor" | 101 | "This repository has a low bus factor, as maintained by a single contributor" |
| 102 | ) | 102 | ) |
| 103 | SECURITY_POLICY_MSG = ( | ||
| 104 | "This repository has neither a security policy nor private" | ||
| 105 | " vulnerability reporting enabled, so there's no clear way to report security issues" | ||
| 106 | ) | ||
| 103 | 107 | ||
| 104 | 108 | ||
| 105 | def load_diff(path): | 109 | def load_diff(path): |
| @@ -214,6 +218,13 @@ def check_bus_factor(owner, repo, token): | |||
| 214 | return None | 218 | return None |
| 215 | 219 | ||
| 216 | 220 | ||
| 221 | def check_security_policy(owner, repo, token): | ||
| 222 | """Return SECURITY_POLICY_MSG if the repo has no security policy or private reporting.""" | ||
| 223 | if utils.has_security_contact(owner, repo, token, session=SESSION, timeout=TIMEOUT) is False: | ||
| 224 | return SECURITY_POLICY_MSG | ||
| 225 | return None | ||
| 226 | |||
| 227 | |||
| 217 | def check_spam_prs(pr_user, token): | 228 | def check_spam_prs(pr_user, token): |
| 218 | """Return list of spam findings based on recent PR activity.""" | 229 | """Return list of spam findings based on recent PR activity.""" |
| 219 | if not pr_user: | 230 | if not pr_user: |
| @@ -393,6 +404,11 @@ def check_repo_signals(diff, pr_user, token, pr_body=""): | |||
| 393 | if finding: | 404 | if finding: |
| 394 | findings.append(finding) | 405 | findings.append(finding) |
| 395 | 406 | ||
| 407 | if SECURITY_POLICY_MSG not in findings: | ||
| 408 | finding = check_security_policy(owner, repo, token) | ||
| 409 | if finding: | ||
| 410 | findings.append(finding) | ||
| 411 | |||
| 396 | return findings | 412 | return findings |
| 397 | 413 | ||
| 398 | 414 | ||
lib/utils/__init__.py +2
| @@ -28,6 +28,7 @@ try: | |||
| 28 | commit_has_bot, | 28 | commit_has_bot, |
| 29 | fetch_repo, | 29 | fetch_repo, |
| 30 | gh_get, | 30 | gh_get, |
| 31 | has_security_contact, | ||
| 31 | parse_github_field, | 32 | parse_github_field, |
| 32 | repo_age_days, | 33 | repo_age_days, |
| 33 | repo_has_license, | 34 | repo_has_license, |
| @@ -58,6 +59,7 @@ __all__ = [ | |||
| 58 | "fetch_repo", | 59 | "fetch_repo", |
| 59 | "fetch_security_report", | 60 | "fetch_security_report", |
| 60 | "gh_get", | 61 | "gh_get", |
| 62 | "has_security_contact", | ||
| 61 | "ios_app_id", | 63 | "ios_app_id", |
| 62 | "ios_days_since_update", | 64 | "ios_days_since_update", |
| 63 | "ios_rating", | 65 | "ios_rating", |
lib/utils/github.py +42
| @@ -67,6 +67,26 @@ def gh_get(path, token, session=None, params=None, timeout=DEFAULT_TIMEOUT, labe | |||
| 67 | return None | 67 | return None |
| 68 | 68 | ||
| 69 | 69 | ||
| 70 | def _gh_graphql(query, variables, token, session=None, timeout=DEFAULT_TIMEOUT, label=""): | ||
| 71 | """POST a GitHub GraphQL query. Returns the `data` dict, else None (needs a token)""" | ||
| 72 | if not token: | ||
| 73 | return None | ||
| 74 | session = session or make_session() | ||
| 75 | try: | ||
| 76 | resp = session.post( | ||
| 77 | "https://api.github.com/graphql", | ||
| 78 | headers={"Authorization": f"bearer {token}"}, | ||
| 79 | json={"query": query, "variables": variables}, timeout=timeout | ||
| 80 | ) | ||
| 81 | body = resp.json() if resp.status_code == 200 else {} | ||
| 82 | if isinstance(body.get("data"), dict) and not body.get("errors"): | ||
| 83 | return body["data"] | ||
| 84 | logging.warning("[%s] GraphQL HTTP %d: %s", label, resp.status_code, body.get("errors")) | ||
| 85 | except Exception as exc: | ||
| 86 | logging.warning("[%s] GraphQL request error: %s", label, exc) | ||
| 87 | return None | ||
| 88 | |||
| 89 | |||
| 70 | def fetch_repo(owner, repo, token, session=None): | 90 | def fetch_repo(owner, repo, token, session=None): |
| 71 | """Fetch GitHub repo metadata, returning None on any error.""" | 91 | """Fetch GitHub repo metadata, returning None on any error.""" |
| 72 | return gh_get(f"/repos/{owner}/{repo}", token, session=session, label="repos") | 92 | return gh_get(f"/repos/{owner}/{repo}", token, session=session, label="repos") |
| @@ -126,6 +146,28 @@ def top_contributor_share(owner, repo, token, session=None, timeout=DEFAULT_TIME | |||
| 126 | return None | 146 | return None |
| 127 | 147 | ||
| 128 | 148 | ||
| 149 | _SECURITY_POLICY_QUERY = ( | ||
| 150 | "query($owner: String!, $name: String!) {" | ||
| 151 | " repository(owner: $owner, name: $name) { isSecurityPolicyEnabled } }" | ||
| 152 | ) | ||
| 153 | |||
| 154 | |||
| 155 | def has_security_contact(owner, repo, token, session=None, timeout=DEFAULT_TIMEOUT): | ||
| 156 | """True if a repo has private vulnerability reporting or a security policy""" | ||
| 157 | pvr = gh_get(f"/repos/{owner}/{repo}/private-vulnerability-reporting", token, | ||
| 158 | session=session, timeout=timeout, label="pvr") | ||
| 159 | pvr = pvr.get("enabled") if isinstance(pvr, dict) else None | ||
| 160 | if pvr is True: | ||
| 161 | return True | ||
| 162 | data = _gh_graphql(_SECURITY_POLICY_QUERY, {"owner": owner, "name": repo}, token, | ||
| 163 | session=session, timeout=timeout, label="security-policy") | ||
| 164 | repo_data = data.get("repository") if data else None | ||
| 165 | policy = repo_data.get("isSecurityPolicyEnabled") if isinstance(repo_data, dict) else None | ||
| 166 | if policy is True: | ||
| 167 | return True | ||
| 168 | return False if pvr is False and policy is False else None | ||
| 169 | |||
| 170 | |||
| 129 | def _days_since(iso_str): | 171 | def _days_since(iso_str): |
| 130 | if not iso_str: | 172 | if not iso_str: |
| 131 | return None | 173 | return None |