| @@ -6,10 +6,10 @@ Checks: |
| 6 | 6 | - https-url: homepage URL uses HTTPS |
| 7 | 7 | - icon-reachable: icon URL does not 404 |
| 8 | 8 | - description-len: description is 50 to 280 chars (over 420 escalates to warn) |
| 9 | | - opensource-github: openSource listings include a github, codeberg or git field |
| 9 | - opensource-github: openSource listings include a repo link (error); not open source is noted (info) |
| 10 | 10 | - duplicate-url: no URL appears in more than one listing |
| 11 | 11 | - androidApp-valid: androidApp is a package name, not a URL |
| 12 | | - iosApp-reachable: App Store URL resolves |
| 12 | - iosApp-valid: iosApp is a valid App Store URL with an app id |
| 13 | 13 | - subreddit-exists: subreddit page exists on reddit.com |
| 14 | 14 | - tosdr-valid: tosdrId still resolves on tosdr.org |
| 15 | 15 | - discord-invite-valid: Discord invite code is still valid |
| @@ -18,10 +18,16 @@ Checks: |
| 18 | 18 | - github-activity: github repo was pushed recently (needs token) |
| 19 | 19 | - github-license: github repo has a license (needs token) |
| 20 | 20 | - github-fork: github repo is not a fork (needs token) |
| 21 | - security-advisories: no open unpatched CVEs (needs API_TOKEN) |
| 22 | - android-trackers: android app has few trackers (1 info, 2+ warn) (needs API_TOKEN) |
| 23 | - ios-app: iOS app exists, is maintained and rated (missing/stale/low-rating warn) (needs API_TOKEN) |
| 24 | - degoogled-compat: android app works on de-googled android (needs API_TOKEN) |
| 25 | - privacy-grade: tosdr privacy grade is B or better (C info, D/E warn) (needs API_TOKEN) |
| 21 | 26 | |
| 22 | 27 | Findings have three severities: error (must fix), warn (should review), info (FYI). |
| 23 | 28 | HTTP 403/406/429 (and 404 on known bot-blocking hosts such as play.google.com) on |
| 24 | | reachability checks is demoted from error to warn. |
| 29 | reachability checks means the probe was rate-limited or blocked, not that the resource is |
| 30 | missing, so it is logged during the run but left out of the results. |
| 25 | 31 | |
| 26 | 32 | Exit codes: |
| 27 | 33 | 1 when pass rate drops below FAIL_PASS_RATE or errors exceed FAIL_MAX_ERRORS (5) |
| @@ -52,7 +58,7 @@ import sys |
| 52 | 58 | from concurrent.futures import ThreadPoolExecutor, as_completed |
| 53 | 59 | from dataclasses import asdict, dataclass, field |
| 54 | 60 | from datetime import datetime, timezone |
| 55 | | from threading import Lock |
| 61 | from threading import Lock, local |
| 56 | 62 | from time import monotonic |
| 57 | 63 | from typing import Callable, Iterable |
| 58 | 64 | from urllib.parse import urlparse |
| @@ -111,12 +117,26 @@ class Finding: |
| 111 | 117 | |
| 112 | 118 | @dataclass |
| 113 | 119 | class Context: |
| 114 | | session: object |
| 115 | 120 | token: str |
| 116 | 121 | timeout: int |
| 122 | api_token: str = "" |
| 117 | 123 | url_occurrences: dict = field(default_factory=dict) |
| 118 | 124 | repo_cache: dict = field(default_factory=dict) |
| 125 | security_cache: dict = field(default_factory=dict) |
| 126 | android_cache: dict = field(default_factory=dict) |
| 127 | privacy_cache: dict = field(default_factory=dict) |
| 128 | ios_cache: dict = field(default_factory=dict) |
| 119 | 129 | repo_lock: Lock = field(default_factory=Lock) |
| 130 | _sessions: local = field(default_factory=local) |
| 131 | |
| 132 | @property |
| 133 | def session(self): |
| 134 | """Per-thread session, since a requests.Session is not safe to share across threads.""" |
| 135 | session = getattr(self._sessions, "value", None) |
| 136 | if session is None: |
| 137 | session = utils.make_session() |
| 138 | self._sessions.value = session |
| 139 | return session |
| 120 | 140 | |
| 121 | 141 | |
| 122 | 142 | @dataclass |
| @@ -124,6 +144,7 @@ class CheckSpec: |
| 124 | 144 | name: str |
| 125 | 145 | scope: str |
| 126 | 146 | needs_github: bool |
| 147 | needs_api: bool |
| 127 | 148 | fn: Callable |
| 128 | 149 | doc: str |
| 129 | 150 | |
| @@ -131,9 +152,11 @@ class CheckSpec: |
| 131 | 152 | CHECKS: dict[str, CheckSpec] = {} |
| 132 | 153 | |
| 133 | 154 | |
| 134 | | def check(name, *, scope="service", needs_github=False): |
| 155 | def check(name, *, scope="service", needs_github=False, needs_api=False): |
| 135 | 156 | def deco(fn): |
| 136 | | CHECKS[name] = CheckSpec(name, scope, needs_github, fn, (fn.__doc__ or "").strip()) |
| 157 | CHECKS[name] = CheckSpec( |
| 158 | name, scope, needs_github, needs_api, fn, (fn.__doc__ or "").strip() |
| 159 | ) |
| 137 | 160 | return fn |
| 138 | 161 | return deco |
| 139 | 162 | |
| @@ -160,21 +183,74 @@ def _get_repo(entry: Entry, ctx: Context): |
| 160 | 183 | return data |
| 161 | 184 | |
| 162 | 185 | |
| 163 | | def _unreachable(field, url, status, default_sev): |
| 164 | | """Return (severity, message). Bot-blocking signatures demote error to warn.""" |
| 165 | | host = urlparse(url).netloc.lower() |
| 166 | | soft = status in _SOFT_HTTP or (status == 404 and host in _SOFT_404_HOSTS) |
| 167 | | sev = "warn" if default_sev == "error" and soft else default_sev |
| 168 | | detail = f"{url} returned HTTP {status}" if status else f"{url} could not be reached" |
| 169 | | return sev, f"{field} is unreachable, {detail}" |
| 186 | def _get_security_report(entry: Entry, ctx: Context): |
| 187 | owner, repo = utils.parse_github_field(entry.service.get("github")) |
| 188 | if not owner: |
| 189 | return None |
| 190 | key = f"{owner}/{repo}" |
| 191 | with ctx.repo_lock: |
| 192 | if key in ctx.security_cache: |
| 193 | return ctx.security_cache[key] |
| 194 | data = utils.fetch_security_report(owner, repo, ctx.api_token, |
| 195 | session=ctx.session, label=entry.name) |
| 196 | with ctx.repo_lock: |
| 197 | ctx.security_cache[key] = data |
| 198 | return data |
| 199 | |
| 200 | |
| 201 | def _get_android(entry: Entry, ctx: Context): |
| 202 | pkg = entry.service.get("androidApp") |
| 203 | if not pkg: |
| 204 | return None |
| 205 | with ctx.repo_lock: |
| 206 | if pkg in ctx.android_cache: |
| 207 | return ctx.android_cache[pkg] |
| 208 | data = utils.fetch_android_app(pkg, ctx.api_token, session=ctx.session, label=entry.name) |
| 209 | with ctx.repo_lock: |
| 210 | ctx.android_cache[pkg] = data |
| 211 | return data |
| 212 | |
| 213 | |
| 214 | def _get_privacy(entry: Entry, ctx: Context): |
| 215 | tid = entry.service.get("tosdrId") |
| 216 | if not tid: |
| 217 | return None |
| 218 | key = str(tid) |
| 219 | with ctx.repo_lock: |
| 220 | if key in ctx.privacy_cache: |
| 221 | return ctx.privacy_cache[key] |
| 222 | data = utils.fetch_privacy(tid, ctx.api_token, session=ctx.session, label=entry.name) |
| 223 | with ctx.repo_lock: |
| 224 | ctx.privacy_cache[key] = data |
| 225 | return data |
| 226 | |
| 227 | |
| 228 | def _get_ios(entry: Entry, ctx: Context): |
| 229 | """Return (report, http_status) for the listing's iOS app, both None if no valid id.""" |
| 230 | app_id = utils.ios_app_id(entry.service.get("iosApp")) |
| 231 | if not app_id: |
| 232 | return None, None |
| 233 | with ctx.repo_lock: |
| 234 | if app_id in ctx.ios_cache: |
| 235 | return ctx.ios_cache[app_id] |
| 236 | result = utils.fetch_ios(entry.service.get("iosApp"), ctx.api_token, |
| 237 | session=ctx.session, label=entry.name, return_status=True) |
| 238 | with ctx.repo_lock: |
| 239 | ctx.ios_cache[app_id] = result |
| 240 | return result |
| 170 | 241 | |
| 171 | 242 | |
| 172 | 243 | def _reachability_finding(entry, check_name, field, url, default_sev, ctx): |
| 173 | 244 | ok, status = utils.check_url(url, ctx.session, ctx.timeout) |
| 174 | 245 | if ok: |
| 175 | 246 | return None |
| 176 | | sev, msg = _unreachable(field, url, status, default_sev) |
| 177 | | return _finding(entry, check_name, sev, msg) |
| 247 | host = urlparse(url).netloc.lower() |
| 248 | if status in _SOFT_HTTP or (status == 404 and host in _SOFT_404_HOSTS): |
| 249 | # Rate-limited or bot-blocked probe, inconclusive so log it but do not report |
| 250 | logging.info("%s for %s inconclusive (HTTP %s) possibly just rate-limited/blocked", check_name, url, status) |
| 251 | return None |
| 252 | detail = f"{url} returned HTTP {status}" if status else f"{url} could not be reached" |
| 253 | return _finding(entry, check_name, default_sev, f"{field} is unreachable, {detail}") |
| 178 | 254 | |
| 179 | 255 | |
| 180 | 256 | @check("url-reachable") |
| @@ -222,14 +298,16 @@ def _description_len(entry: Entry, ctx: Context) -> Iterable[Finding]: |
| 222 | 298 | |
| 223 | 299 | @check("opensource-github") |
| 224 | 300 | def _opensource_github(entry: Entry, ctx: Context) -> Iterable[Finding]: |
| 225 | | """openSource: true services must include a github, codeberg or git field.""" |
| 301 | """openSource: true needs a repo link (error); not open source is noted (info).""" |
| 226 | 302 | svc = entry.service |
| 227 | | if svc.get("openSource") is True and not ( |
| 228 | | svc.get("github") or svc.get("codeberg") or svc.get("git") |
| 229 | | ): |
| 303 | has_repo = svc.get("github") or svc.get("codeberg") or svc.get("git") |
| 304 | if svc.get("openSource") is True and not has_repo: |
| 230 | 305 | yield _finding(entry, "opensource-github", "error", |
| 231 | | "marked openSource but missing a repository link " |
| 232 | | "(`github`, `codeberg` or `git`)") |
| 306 | "marked openSource but missing a repository link ") |
| 307 | elif svc.get("openSource") is False or not has_repo: |
| 308 | reason = "openSource is false" if svc.get("openSource") is False else "no repository linked" |
| 309 | yield _finding(entry, "opensource-github", "info", |
| 310 | f"not open source ({reason})") |
| 233 | 311 | |
| 234 | 312 | |
| 235 | 313 | @check("androidApp-valid") |
| @@ -241,14 +319,13 @@ def _android_app_valid(entry: Entry, ctx: Context) -> Iterable[Finding]: |
| 241 | 319 | f"androidApp {val} is not a package name (expected com.example.app)") |
| 242 | 320 | |
| 243 | 321 | |
| 244 | | @check("iosApp-reachable") |
| 245 | | def _iosapp_reachable(entry: Entry, ctx: Context) -> Iterable[Finding]: |
| 246 | | """iOS App Store link must resolve.""" |
| 322 | @check("iosApp-valid") |
| 323 | def _iosapp_valid(entry: Entry, ctx: Context) -> Iterable[Finding]: |
| 324 | """iosApp must be an App Store URL with an app id.""" |
| 247 | 325 | url = entry.service.get("iosApp") |
| 248 | | if url: |
| 249 | | f = _reachability_finding(entry, "iosApp-reachable", "iosApp", url, "warn", ctx) |
| 250 | | if f: |
| 251 | | yield f |
| 326 | if url and not utils.ios_app_id(url): |
| 327 | yield _finding(entry, "iosApp-valid", "warn", |
| 328 | f"iosApp {url} is not a valid App Store URL (expected .../idNNNN)") |
| 252 | 329 | |
| 253 | 330 | |
| 254 | 331 | @check("subreddit-exists") |
| @@ -344,6 +421,81 @@ def _github_license(entry: Entry, ctx: Context) -> Iterable[Finding]: |
| 344 | 421 | yield _finding(entry, "github-license", "warn", "repository has no declared license") |
| 345 | 422 | |
| 346 | 423 | |
| 424 | @check("security-advisories", needs_api=True) |
| 425 | def _security_advisories(entry: Entry, ctx: Context) -> Iterable[Finding]: |
| 426 | """No open unpatched CVEs (low/medium warn, high/critical error).""" |
| 427 | if not entry.service.get("github"): |
| 428 | return |
| 429 | low_med, high_crit = utils.unpatched_advisories(_get_security_report(entry, ctx)) |
| 430 | if high_crit: |
| 431 | yield _finding(entry, "security-advisories", "error", |
| 432 | f"{high_crit} open high/critical " |
| 433 | f"advisor{'ies' if high_crit != 1 else 'y'}") |
| 434 | if low_med: |
| 435 | yield _finding(entry, "security-advisories", "warn", |
| 436 | f"{low_med} open low/medium " |
| 437 | f"advisor{'ies' if low_med != 1 else 'y'}") |
| 438 | |
| 439 | |
| 440 | @check("android-trackers", needs_api=True) |
| 441 | def _android_trackers(entry: Entry, ctx: Context) -> Iterable[Finding]: |
| 442 | """Android app has few trackers (1 info, 2+ warn).""" |
| 443 | if not entry.service.get("androidApp"): |
| 444 | return |
| 445 | count = utils.tracker_count(_get_android(entry, ctx)) |
| 446 | if not count: |
| 447 | return |
| 448 | sev = "info" if count == 1 else "warn" |
| 449 | yield _finding(entry, "android-trackers", sev, |
| 450 | f"Android app reports {count} tracker{'s' if count != 1 else ''}") |
| 451 | |
| 452 | |
| 453 | @check("ios-app", needs_api=True) |
| 454 | def _ios_app(entry: Entry, ctx: Context) -> Iterable[Finding]: |
| 455 | """iOS app exists, is maintained and rated (missing/stale/<2 stars warn).""" |
| 456 | if not utils.ios_app_id(entry.service.get("iosApp")): |
| 457 | return |
| 458 | report, status = _get_ios(entry, ctx) |
| 459 | if status == 404: |
| 460 | yield _finding(entry, "ios-app", "warn", |
| 461 | "iOS app not found on the App Store (may have been removed)") |
| 462 | return |
| 463 | days = utils.ios_days_since_update(report) |
| 464 | if days is not None and days >= 365: |
| 465 | yield _finding(entry, "ios-app", "warn", |
| 466 | f"iOS app not updated in over a year (last release {days} days ago)") |
| 467 | rating, count = utils.ios_rating(report) |
| 468 | if count and rating is not None and rating < 2: |
| 469 | yield _finding(entry, "ios-app", "warn", |
| 470 | f"iOS app is rated below 2 stars ({rating:.1f} from {count:,} ratings)") |
| 471 | |
| 472 | |
| 473 | @check("degoogled-compat", needs_api=True) |
| 474 | def _degoogled_compat(entry: Entry, ctx: Context) -> Iterable[Finding]: |
| 475 | """Android app works on de-Googled Android (broken warn, limited info).""" |
| 476 | if not entry.service.get("androidApp"): |
| 477 | return |
| 478 | status = utils.degoogled_status(_get_android(entry, ctx)) |
| 479 | if status == "broken": |
| 480 | yield _finding(entry, "degoogled-compat", "warn", |
| 481 | "Android app is broken on de-Googled Android") |
| 482 | elif status == "bronze": |
| 483 | yield _finding(entry, "degoogled-compat", "info", |
| 484 | "Android app has limited de-Googled support") |
| 485 | |
| 486 | |
| 487 | @check("privacy-grade", needs_api=True) |
| 488 | def _privacy_grade(entry: Entry, ctx: Context) -> Iterable[Finding]: |
| 489 | """ToS;DR privacy grade is B or better (C info, D/E warn).""" |
| 490 | if not entry.service.get("tosdrId"): |
| 491 | return |
| 492 | grade = utils.privacy_grade(_get_privacy(entry, ctx)) |
| 493 | if grade == "C": |
| 494 | yield _finding(entry, "privacy-grade", "info", "privacy policy has minor concerns") |
| 495 | elif grade in ("D", "E"): |
| 496 | yield _finding(entry, "privacy-grade", "warn", f"privacy policy has major issues (graded: {grade})") |
| 497 | |
| 498 | |
| 347 | 499 | @check("duplicate-url", scope="global") |
| 348 | 500 | def _duplicate_url(entries, ctx: Context) -> Iterable[Finding]: |
| 349 | 501 | """No two listings share the same homepage URL.""" |
| @@ -375,11 +527,11 @@ def _install_sigint(): |
| 375 | 527 | signal.signal(signal.SIGINT, handler) |
| 376 | 528 | |
| 377 | 529 | |
| 378 | | def build_context(args, data, token): |
| 530 | def build_context(args, data, token, api_token): |
| 379 | 531 | ctx = Context( |
| 380 | | session=utils.make_session(), |
| 381 | 532 | token=token, |
| 382 | 533 | timeout=args.timeout, |
| 534 | api_token=api_token, |
| 383 | 535 | ) |
| 384 | 536 | for cat, sec, svc in utils.iter_services(data): |
| 385 | 537 | url = _normalize_url(svc.get("url")) |
| @@ -654,11 +806,13 @@ def main(): |
| 654 | 806 | if args.list_checks: |
| 655 | 807 | for name, spec in CHECKS.items(): |
| 656 | 808 | tag = colors["dim"](" (needs GITHUB_TOKEN)") if spec.needs_github else "" |
| 809 | tag += colors["dim"](" (needs API_TOKEN)") if spec.needs_api else "" |
| 657 | 810 | print(f" {colors['cyan'](name.ljust(22))} {spec.doc}{tag}") |
| 658 | 811 | return |
| 659 | 812 | |
| 660 | 813 | enabled = resolve_enabled(args.only, args.skip) |
| 661 | 814 | token = args.token or os.environ.get("GITHUB_TOKEN", "") |
| 815 | api_token = os.environ.get("API_TOKEN", "") |
| 662 | 816 | |
| 663 | 817 | if not token: |
| 664 | 818 | gh_checks = [n for n in enabled if CHECKS[n].needs_github] |
| @@ -670,6 +824,16 @@ def main(): |
| 670 | 824 | ) |
| 671 | 825 | enabled = [n for n in enabled if not CHECKS[n].needs_github] |
| 672 | 826 | |
| 827 | if not api_token: |
| 828 | api_checks = [n for n in enabled if CHECKS[n].needs_api] |
| 829 | if api_checks: |
| 830 | logging.warning( |
| 831 | "API_TOKEN not set, skipping API checks (%s). " |
| 832 | "Export API_TOKEN to enable them.", |
| 833 | ", ".join(api_checks), |
| 834 | ) |
| 835 | enabled = [n for n in enabled if not CHECKS[n].needs_api] |
| 836 | |
| 673 | 837 | if not enabled: |
| 674 | 838 | logging.error("No checks to run after filters.") |
| 675 | 839 | sys.exit(2) |
| @@ -689,7 +853,7 @@ def main(): |
| 689 | 853 | args.category, args.section, args.service) |
| 690 | 854 | sys.exit(2) |
| 691 | 855 | |
| 692 | | ctx = build_context(args, data, token) |
| 856 | ctx = build_context(args, data, token, api_token) |
| 693 | 857 | logging.info("Reviewing %d service(s) with %d check(s): %s", |
| 694 | 858 | len(entries), len(enabled), ", ".join(enabled)) |
| 695 | 859 | |