[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6R5EGKM58HZKYTG0E8WPR72":3,"skill-same:01M6R5EGKM58HZKYTG0E8WPR72":61},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":36,"linkOnly":37,"markdownContent":38,"markdownBody":39,"frontMatter":40,"refName":41,"commitSha":42,"skillDirectory":43,"forksCount":13,"repositoryHtmlUrl":44,"repositoryHomepageUrl":6,"ownerHtmlUrl":45,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":46,"install":47,"resources":60},"01M6R5EGKM58HZKYTG0E8WPR72","abuse-detection",null,"Detect and analyze abusive accounts on Pollinations. IP clustering, multi-signal scoring, ban recommendations. Use when investigating abuse, bot farms, or suspicious usage patterns.","APPLEPIE6969\u002FPollinations","APPLEPIE6969","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F242827480?v=4","01M6R5D0EAJN2DFJB3X6QTDANJ","01M6R5D0K2TSEDG15DK4M26BHH",0,"MIT","https:\u002F\u002Fgithub.com\u002FAPPLEPIE6969\u002FPollinations\u002Fblob\u002Fwan-aspect-ratio-fix\u002F.claude\u002Fskills\u002Fabuse-detection\u002FSKILL.md",[],[18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35],"abuse detection","detection","signal scoring","when","signal","usage","multi","detect","recommendations","ip","bot","scoring","patterns","pollinations","use","analyze","clustering","suspicious","2026-11-10 10:12:30",false,"---\nname: abuse-detection\ndescription: Detect and analyze abusive accounts on Pollinations. IP clustering, multi-signal scoring, ban recommendations. Use when investigating abuse, bot farms, or suspicious usage patterns.\n---\n\n# Requirements\n\n- **Tinybird CLI** (`tb`): Must be authenticated\n- Run queries from `enter.pollinations.ai\u002Fobservability\u002F` (has `.tinyb` config)\n- **Cloudflare D1** access for banning users (via wrangler)\n\n**Tinybird query pattern:**\n```bash\ncd enter.pollinations.ai\u002Fobservability\ntb --cloud sql \"SELECT ... FROM generation_event_v2 ...\"\n```\n\n> **Workspace**: This skill is **prod-only**. The `.tinyb` in `observability\u002F` points to the `pollinations_enter` workspace (prod traffic). Staging traffic lives in `pollinations_enter_staging` and has no real abuse signal — don't waste time analyzing it. To pin a query to staging anyway (e.g. testing a new scoring query), set `TB_TOKEN=\u003Cstaging_admin_token>` for that one command.\n\n> **Quoting**: Use double quotes for the SQL string. Use single quotes inside SQL. Avoid `!=` with `$'...'` shell quoting (escaping issues) — prefer `NOT IN ('undefined', '')` instead.\n\n> **`tb` CLI caps at 100 rows.** For large result sets, use the HTTP API:\n> ```bash\n> TB_TOKEN=$(python3 -c \"import json; print(json.load(open('.tinyb'))['token'])\")\n> curl -s \"https:\u002F\u002Fapi.europe-west2.gcp.tinybird.co\u002Fv0\u002Fsql\" \\\n>   -H \"Authorization: Bearer $TB_TOKEN\" \\\n>   --data-urlencode \"q=SELECT ... FORMAT JSONCompact\" | python3 -c \"import json,sys; ...\"\n> ```\n\n---\n\n# Composite Abuse Score (0-100)\n\nSix signals, each weighted independently:\n\n| Signal | Max Points | Threshold | What it catches |\n|--------|-----------|-----------|-----------------|\n| IP cluster size | 30 | `cluster * 0.15` | Multiple users sharing same IP hash |\n| Zero pack spend | 15 | `spend = 0` | No paid pack usage |\n| Error rate | 15 | `>= 95%` (15pts), `>= 70%` (10pts) | Bots hammering failing endpoints |\n| Moderation flags | 15 | `>= 90%` sexual (15pts), `>= 50%` (8pts) | NSFW generation bots |\n| Disposable email | 15 | hotmail\u002Foutlook\u002Fproton + no spend | Random-string throwaway emails |\n| IP rotation | 10 | `>= 50` IPs (10pts), `>= 20` (5pts) | Rotating through many exit IPs |\n\n**Score interpretation:**\n\n| Score | Action | False positive risk |\n|-------|--------|-------------------|\n| 90-100 | Ban immediately | Very low |\n| 70-89 | Ban after quick review | Low |\n| 40-69 | Manual review needed | Medium |\n| 10-39 | Monitor only | High — many legit users with NSFW or errors |\n| 0-9 | Clean | N\u002FA |\n\n---\n\n# Quick Ban Criteria (High Confidence)\n\nFor accounts generating massive failing traffic with no paid pack usage, a simpler signal is sufficient:\n\n```\nzero pack spend + 95%+ error rate + 1000+ requests\u002Fweek\n```\n\nThis catches bot farm accounts that are already rate-limited (no spendable balance) but still hammering the API with failing requests. These accounts waste server resources with zero legitimate usage.\n\n**Query:**\n\n```sql\nSELECT user_id\nFROM (\n    SELECT\n        g.user_id,\n        count() as total_reqs,\n        round(sumIf(g.total_price, g.selected_meter_slug IN ('v1:meter:pack', 'local:pack')), 4) as pack_spend,\n        countIf(g.response_status >= 400) * 100.0 \u002F count() as err_pct\n    FROM generation_event_v2 g\n    WHERE g.start_time >= now() - INTERVAL 7 DAY\n        AND g.user_id NOT IN ('undefined', '')\n    GROUP BY g.user_id\n    HAVING total_reqs >= 1000\n)\nWHERE pack_spend = 0 AND err_pct >= 95\n```\n\n> **Note**: `tb --cloud sql` caps output at 100 rows. For large result sets, use the Tinybird HTTP API with `FORMAT JSONCompact`.\n\n---\n\n# Key Queries\n\n## 1. Full Abuse Scoring Query\n\nReturns all users with abuse score, sorted by score descending. The spend signal uses `selected_meter_slug` to distinguish paid pack consumption from the other active balance bucket.\n\n```sql\nSELECT\n    user_id, github_username, email,\n    total_reqs, pack_spend, total_spend, max_ip_cluster, distinct_ips,\n    round(err_pct, 1) as err_pct, round(sex_pct, 1) as sex_pct,\n    abuse_score\nFROM (\n    SELECT\n        g.user_id, u.github_username, u.email,\n        count() as total_reqs,\n        round(sumIf(g.total_price, g.selected_meter_slug IN ('v1:meter:pack', 'local:pack')), 4) as pack_spend,\n        round(sum(g.total_price), 4) as total_spend,\n        max(coalesce(ips.ip_cluster_size, 0)) as max_ip_cluster,\n        countDistinct(g.ip_hash) as distinct_ips,\n        countIf(g.response_status >= 400) * 100.0 \u002F count() as err_pct,\n        countIf(g.moderation_prompt_sexual_severity NOT IN ('safe', '')) * 100.0 \u002F count() as sex_pct,\n        round(\n            least(30, max(coalesce(ips.ip_cluster_size, 0)) * 0.15) +\n            multiIf(\n                splitByChar('@', u.email)[2] = 'proton.me' AND pack_spend = 0, 15,\n                splitByChar('@', u.email)[2] = 'hotmail.com' AND pack_spend = 0, 12,\n                splitByChar('@', u.email)[2] = 'outlook.com' AND pack_spend = 0, 10,\n                0) +\n            if(pack_spend = 0, 15, 0) +\n            if(countIf(g.response_status >= 400) * 100.0 \u002F count() >= 95, 15,\n               if(countIf(g.response_status >= 400) * 100.0 \u002F count() >= 70, 10, 0)) +\n            if(countIf(g.moderation_prompt_sexual_severity NOT IN ('safe', '')) * 100.0 \u002F count() >= 90, 15,\n               if(countIf(g.moderation_prompt_sexual_severity NOT IN ('safe', '')) * 100.0 \u002F count() >= 50, 8, 0)) +\n            if(countDistinct(g.ip_hash) >= 50, 10, if(countDistinct(g.ip_hash) >= 20, 5, 0))\n        , 0) as abuse_score\n    FROM generation_event_v2 g\n    LEFT JOIN d1_user u ON g.user_id = u.id\n        AND u.synced_at = (SELECT max(synced_at) FROM d1_user)\n    LEFT JOIN (\n        SELECT ip_hash, count(DISTINCT user_id) as ip_cluster_size\n        FROM generation_event_v2\n        WHERE start_time >= now() - INTERVAL 7 DAY\n            AND ip_hash NOT IN ('undefined', '')\n            AND user_id NOT IN ('undefined', '')\n        GROUP BY ip_hash\n    ) ips ON g.ip_hash = ips.ip_hash\n    WHERE g.start_time >= now() - INTERVAL 7 DAY\n        AND g.user_id NOT IN ('undefined', '')\n    GROUP BY g.user_id, u.github_username, u.email\n    HAVING total_reqs >= 5\n)\nWHERE abuse_score >= 40\nORDER BY abuse_score DESC, total_reqs DESC\nLIMIT 100\n```\n\n## 2. IP Cluster Analysis\n\nFind IPs shared by many users (bot farm detection):\n\n```sql\nSELECT\n    ip_subnet, ip_hash,\n    count(DISTINCT user_id) as unique_users,\n    count() as total_requests,\n    dateDiff('minute', min(start_time), max(start_time)) as span_min\nFROM generation_event_v2\nWHERE start_time >= now() - INTERVAL 7 DAY\n    AND ip_hash NOT IN ('undefined', '')\n    AND user_id NOT IN ('undefined', '')\nGROUP BY ip_hash, ip_subnet\nHAVING unique_users >= 10\nORDER BY unique_users DESC\nLIMIT 30\n```\n\n## 3. User Details for an IP Cluster\n\n```sql\nSELECT DISTINCT\n    g.user_id, u.github_username, u.email,\n    sumIf(g.total_price, g.selected_meter_slug IN ('v1:meter:pack', 'local:pack')) as pack_spend,\n    sum(g.total_price) as total_spend\nFROM generation_event_v2 g\nLEFT JOIN d1_user u ON g.user_id = u.id\n    AND u.synced_at = (SELECT max(synced_at) FROM d1_user)\nWHERE g.start_time >= now() - INTERVAL 7 DAY\n    AND g.ip_hash = '\u003CIP_HASH_HERE>'\n    AND g.user_id NOT IN ('undefined', '')\nGROUP BY g.user_id, u.github_username, u.email\nORDER BY pack_spend DESC\n```\n\n## 4. Score Distribution (Overview)\n\n```sql\nSELECT\n    multiIf(abuse_score >= 90, '90-100 definite',\n            abuse_score >= 70, '70-89 likely',\n            abuse_score >= 40, '40-69 suspicious',\n            abuse_score >= 10, '10-39 low_risk',\n            '0-9 clean') as bucket,\n    count() as users,\n    round(sum(total_spend), 2) as spend,\n    sum(total_reqs) as requests\nFROM ( \u002F* ... full scoring subquery from #1 ... *\u002F )\nGROUP BY bucket\nORDER BY bucket DESC\n```\n\n## 5. Extract User IDs for Banning\n\n```sql\nSELECT user_id\nFROM ( \u002F* ... full scoring subquery from #1 ... *\u002F )\nWHERE abuse_score >= 90\n```\n\n---\n\n# Known False Positive Patterns\n\n**Always check before banning:**\n\n| Pattern | Why it's a false positive | How to detect |\n|---------|--------------------------|---------------|\n| **Cloudflare WARP\u002FWorkers** | IPv6 `2a06:98c0:3600::` — legit users behind Cloudflare | Check `ip_subnet` starts with `2a06:98c0` |\n| **VPN\u002Fproxy clusters** | Multiple real users behind same VPN exit | Check if cluster has paying users with real emails |\n| **Chinese CGNAT** | Mobile carriers (China Mobile\u002FUnicom\u002FTelecom) share IPs via NAT | Cross-reference with email pattern + spend |\n| **Free balance usage** | Accounts show small \"spend\" from non-pack balance, not real payment | Check `pack_spend` — only pack spend is real payment |\n| **High NSFW, legit user** | Some paying users generate NSFW content legitimately | Check pack spend > $5 — real customers |\n\n**Safe to ban (high confidence):**\n- Zero pack spend + 95%+ error rate + 1000+ requests\u002Fweek\n- Score >= 90 + hotmail\u002Foutlook random email + zero pack spend\n- Score >= 70 + IP cluster >= 100 + zero pack spend\n- Disposable email (hotmail\u002Foutlook\u002Fproton\u002Fqq\u002Fmail.ru\u002Fvk.com\u002Fanonaddy\u002Fanondrop\u002Frambler\u002Fgmx\u002Fyandex) + error >= 95% + $0 pack spend\n- 100% error rate + $0 pack spend (zero successful requests ever)\n- 99%+ error rate + 1000+ requests\u002Fweek (hammering)\n- Multi-account cluster (same email root, e.g. `reksely`\u002F`notreksely`\u002F`rekselicha`)\n\n**Needs review:**\n- Any account with pack spend > $2 (could be real customer)\n- Accounts on Cloudflare IPs (`2a06:98c0:*`)\n- Accounts with real-looking Gmail addresses\n- Accounts with 90-95% error rate but some successful pack spend (may be bad integration, not abuse)\n\n---\n\n# Banning Users\n\n## How Banning Works\n\nThe ban system uses **Better Auth** fields on the `user` table in Cloudflare D1:\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `banned` | boolean (integer 0\u002F1) | Set to `1` to ban |\n| `ban_reason` | text | Shown in 403 error response |\n| `ban_expires` | integer (epoch ms) | `NULL` for permanent, epoch ms for temporary |\n\n**Enforcement** (`src\u002Fmiddleware\u002Fauth.ts`):\n- `assertNotBanned()` runs on every authenticated request (session + API key)\n- If `banned = 1` and not expired → HTTP 403 with ban reason\n- If `ban_expires` is set and has passed → ban is automatically lifted\n\n**There is no admin API for banning** — use `wrangler d1 execute` directly.\n\n## Ban Commands\n\n```bash\n# Single user ban (from enter.pollinations.ai\u002F directory)\nnpx wrangler d1 execute production-pollinations-enter-db --remote \\\n  --command \"UPDATE user SET banned = 1, ban_reason = 'Bot farm abuse' WHERE id = '\u003CUSER_ID>'\"\n\n# Batch ban (from a file of user IDs, one per line)\nIDS=$(cat user_ids_to_ban.txt | sed \"s\u002F^\u002F'\u002F;s\u002F$\u002F'\u002F\" | paste -sd, -)\nnpx wrangler d1 execute production-pollinations-enter-db --remote \\\n  --command \"UPDATE user SET banned = 1, ban_reason = 'Automated: bot farm abuse' WHERE id IN ($IDS)\"\n\n# Unban a user (if false positive)\nnpx wrangler d1 execute production-pollinations-enter-db --remote \\\n  --command \"UPDATE user SET banned = 0, ban_reason = NULL WHERE id = '\u003CUSER_ID>'\"\n\n# Temporary ban (expires after 7 days)\nnpx wrangler d1 execute production-pollinations-enter-db --remote \\\n  --command \"UPDATE user SET banned = 1, ban_reason = 'Temporary: rate abuse', ban_expires = $(date -v+7d +%s)000 WHERE id = '\u003CUSER_ID>'\"\n```\n\n**D1 database names:**\n- Production: `production-pollinations-enter-db`\n- Staging: `staging-pollinations-enter-db`\n- Development: `development-pollinations-enter-db`\n\n---\n\n# Abuse Profile: Chinese Bot Farm (March 2026)\n\n**Characteristics discovered:**\n- **Scale**: 234+ accounts, 6.4M requests\u002Fweek (23% of all traffic)\n- **IPs**: Chinese residential ISPs (China Telecom, Unicom, Mobile) — 60+ distinct IPs per user across 50+ subnets\n- **Emails**: Random strings at hotmail.com\u002Foutlook.com\u002Fproton.me (e.g., `lhanbqkf6005@hotmail.com`)\n- **Usernames**: Gibberish GitHub usernames (e.g., `bomteupted-bsfo`, `jwolfwersenmroom`)\n- **Behavior**: 100% image generation, 100% error rate, 100% NSFW moderation flags\n- **Spend**: $0 pack spend (small non-pack balance usage at most)\n- **Account age**: All created within days of each other (Feb 2026)\n\n---\n\n# Data Sources\n\n| Table | Key columns for abuse |\n|-------|----------------------|\n| `generation_event_v2` | `user_id`, `ip_hash`, `ip_subnet`, `response_status`, `total_price`, `selected_meter_slug`, `moderation_prompt_*`, `event_type` |\n| `d1_user` | `id`, `email`, `github_username`, `banned`, `banReason`, `created_at` |\n\n**IP implementation** (`src\u002Fmiddleware\u002Ftrack.ts`):\n- `ip_hash`: Salted SHA-256 of full IP (irreversible)\n- `ip_subnet`: Truncated to \u002F24 (IPv4) or \u002F48 (IPv6)\n- Source: `cf-connecting-ip` header\n\n---\n\n# Action Log\n\n| Date | Action | Count | Details |\n|------|--------|-------|---------|\n| 2026-03-06 | Banned bot farm | 277 | IP cluster ≥100, 95%+ errors, $0 pack spend |\n| 2026-03-06 | Rate-limited bot farm | 42 | Same bot farm, no pack spend |\n| 2026-03-06 | Rate-limited bot farm | 59 | Multi-signal: IP clusters, gibberish suffixes, disposable emails, hammering |\n\n---\n\n# Notes\n\n- **IP coverage**: Started 2026-03-06, ~19% user coverage initially. Re-run analysis as coverage grows.\n- **d1_user sync lag**: The `d1_user` table in Tinybird syncs periodically (not real-time). After banning on D1, Tinybird data is stale — verify actions on D1 directly.\n- **Pack spend is the strongest payment signal** for abuse review. Total generation spend can include non-pack balance-bucket usage, so filter on `pack_spend` to catch accounts with no real payment.\n- **Gibberish suffix usernames**: Bot farms use GitHub usernames with suffixes like `-boop`, `-a11y`, `-max`, `-sudo`, `-cmd`, `-stack`, `-pixel`, `-dot`, `-beep`, `-commits`, `-ops`, `-dotcom`, `-lang`, `-bit`. These are auto-generated.\n- Consider adding: account age signal, GitHub account age, user-agent clustering\n","# Requirements\n\n- **Tinybird CLI** (`tb`): Must be authenticated\n- Run queries from `enter.pollinations.ai\u002Fobservability\u002F` (has `.tinyb` config)\n- **Cloudflare D1** access for banning users (via wrangler)\n\n**Tinybird query pattern:**\n```bash\ncd enter.pollinations.ai\u002Fobservability\ntb --cloud sql \"SELECT ... FROM generation_event_v2 ...\"\n```\n\n> **Workspace**: This skill is **prod-only**. The `.tinyb` in `observability\u002F` points to the `pollinations_enter` workspace (prod traffic). Staging traffic lives in `pollinations_enter_staging` and has no real abuse signal — don't waste time analyzing it. To pin a query to staging anyway (e.g. testing a new scoring query), set `TB_TOKEN=\u003Cstaging_admin_token>` for that one command.\n\n> **Quoting**: Use double quotes for the SQL string. Use single quotes inside SQL. Avoid `!=` with `$'...'` shell quoting (escaping issues) — prefer `NOT IN ('undefined', '')` instead.\n\n> **`tb` CLI caps at 100 rows.** For large result sets, use the HTTP API:\n> ```bash\n> TB_TOKEN=$(python3 -c \"import json; print(json.load(open('.tinyb'))['token'])\")\n> curl -s \"https:\u002F\u002Fapi.europe-west2.gcp.tinybird.co\u002Fv0\u002Fsql\" \\\n>   -H \"Authorization: Bearer $TB_TOKEN\" \\\n>   --data-urlencode \"q=SELECT ... FORMAT JSONCompact\" | python3 -c \"import json,sys; ...\"\n> ```\n\n---\n\n# Composite Abuse Score (0-100)\n\nSix signals, each weighted independently:\n\n| Signal | Max Points | Threshold | What it catches |\n|--------|-----------|-----------|-----------------|\n| IP cluster size | 30 | `cluster * 0.15` | Multiple users sharing same IP hash |\n| Zero pack spend | 15 | `spend = 0` | No paid pack usage |\n| Error rate | 15 | `>= 95%` (15pts), `>= 70%` (10pts) | Bots hammering failing endpoints |\n| Moderation flags | 15 | `>= 90%` sexual (15pts), `>= 50%` (8pts) | NSFW generation bots |\n| Disposable email | 15 | hotmail\u002Foutlook\u002Fproton + no spend | Random-string throwaway emails |\n| IP rotation | 10 | `>= 50` IPs (10pts), `>= 20` (5pts) | Rotating through many exit IPs |\n\n**Score interpretation:**\n\n| Score | Action | False positive risk |\n|-------|--------|-------------------|\n| 90-100 | Ban immediately | Very low |\n| 70-89 | Ban after quick review | Low |\n| 40-69 | Manual review needed | Medium |\n| 10-39 | Monitor only | High — many legit users with NSFW or errors |\n| 0-9 | Clean | N\u002FA |\n\n---\n\n# Quick Ban Criteria (High Confidence)\n\nFor accounts generating massive failing traffic with no paid pack usage, a simpler signal is sufficient:\n\n```\nzero pack spend + 95%+ error rate + 1000+ requests\u002Fweek\n```\n\nThis catches bot farm accounts that are already rate-limited (no spendable balance) but still hammering the API with failing requests. These accounts waste server resources with zero legitimate usage.\n\n**Query:**\n\n```sql\nSELECT user_id\nFROM (\n    SELECT\n        g.user_id,\n        count() as total_reqs,\n        round(sumIf(g.total_price, g.selected_meter_slug IN ('v1:meter:pack', 'local:pack')), 4) as pack_spend,\n        countIf(g.response_status >= 400) * 100.0 \u002F count() as err_pct\n    FROM generation_event_v2 g\n    WHERE g.start_time >= now() - INTERVAL 7 DAY\n        AND g.user_id NOT IN ('undefined', '')\n    GROUP BY g.user_id\n    HAVING total_reqs >= 1000\n)\nWHERE pack_spend = 0 AND err_pct >= 95\n```\n\n> **Note**: `tb --cloud sql` caps output at 100 rows. For large result sets, use the Tinybird HTTP API with `FORMAT JSONCompact`.\n\n---\n\n# Key Queries\n\n## 1. Full Abuse Scoring Query\n\nReturns all users with abuse score, sorted by score descending. The spend signal uses `selected_meter_slug` to distinguish paid pack consumption from the other active balance bucket.\n\n```sql\nSELECT\n    user_id, github_username, email,\n    total_reqs, pack_spend, total_spend, max_ip_cluster, distinct_ips,\n    round(err_pct, 1) as err_pct, round(sex_pct, 1) as sex_pct,\n    abuse_score\nFROM (\n    SELECT\n        g.user_id, u.github_username, u.email,\n        count() as total_reqs,\n        round(sumIf(g.total_price, g.selected_meter_slug IN ('v1:meter:pack', 'local:pack')), 4) as pack_spend,\n        round(sum(g.total_price), 4) as total_spend,\n        max(coalesce(ips.ip_cluster_size, 0)) as max_ip_cluster,\n        countDistinct(g.ip_hash) as distinct_ips,\n        countIf(g.response_status >= 400) * 100.0 \u002F count() as err_pct,\n        countIf(g.moderation_prompt_sexual_severity NOT IN ('safe', '')) * 100.0 \u002F count() as sex_pct,\n        round(\n            least(30, max(coalesce(ips.ip_cluster_size, 0)) * 0.15) +\n            multiIf(\n                splitByChar('@', u.email)[2] = 'proton.me' AND pack_spend = 0, 15,\n                splitByChar('@', u.email)[2] = 'hotmail.com' AND pack_spend = 0, 12,\n                splitByChar('@', u.email)[2] = 'outlook.com' AND pack_spend = 0, 10,\n                0) +\n            if(pack_spend = 0, 15, 0) +\n            if(countIf(g.response_status >= 400) * 100.0 \u002F count() >= 95, 15,\n               if(countIf(g.response_status >= 400) * 100.0 \u002F count() >= 70, 10, 0)) +\n            if(countIf(g.moderation_prompt_sexual_severity NOT IN ('safe', '')) * 100.0 \u002F count() >= 90, 15,\n               if(countIf(g.moderation_prompt_sexual_severity NOT IN ('safe', '')) * 100.0 \u002F count() >= 50, 8, 0)) +\n            if(countDistinct(g.ip_hash) >= 50, 10, if(countDistinct(g.ip_hash) >= 20, 5, 0))\n        , 0) as abuse_score\n    FROM generation_event_v2 g\n    LEFT JOIN d1_user u ON g.user_id = u.id\n        AND u.synced_at = (SELECT max(synced_at) FROM d1_user)\n    LEFT JOIN (\n        SELECT ip_hash, count(DISTINCT user_id) as ip_cluster_size\n        FROM generation_event_v2\n        WHERE start_time >= now() - INTERVAL 7 DAY\n            AND ip_hash NOT IN ('undefined', '')\n            AND user_id NOT IN ('undefined', '')\n        GROUP BY ip_hash\n    ) ips ON g.ip_hash = ips.ip_hash\n    WHERE g.start_time >= now() - INTERVAL 7 DAY\n        AND g.user_id NOT IN ('undefined', '')\n    GROUP BY g.user_id, u.github_username, u.email\n    HAVING total_reqs >= 5\n)\nWHERE abuse_score >= 40\nORDER BY abuse_score DESC, total_reqs DESC\nLIMIT 100\n```\n\n## 2. IP Cluster Analysis\n\nFind IPs shared by many users (bot farm detection):\n\n```sql\nSELECT\n    ip_subnet, ip_hash,\n    count(DISTINCT user_id) as unique_users,\n    count() as total_requests,\n    dateDiff('minute', min(start_time), max(start_time)) as span_min\nFROM generation_event_v2\nWHERE start_time >= now() - INTERVAL 7 DAY\n    AND ip_hash NOT IN ('undefined', '')\n    AND user_id NOT IN ('undefined', '')\nGROUP BY ip_hash, ip_subnet\nHAVING unique_users >= 10\nORDER BY unique_users DESC\nLIMIT 30\n```\n\n## 3. User Details for an IP Cluster\n\n```sql\nSELECT DISTINCT\n    g.user_id, u.github_username, u.email,\n    sumIf(g.total_price, g.selected_meter_slug IN ('v1:meter:pack', 'local:pack')) as pack_spend,\n    sum(g.total_price) as total_spend\nFROM generation_event_v2 g\nLEFT JOIN d1_user u ON g.user_id = u.id\n    AND u.synced_at = (SELECT max(synced_at) FROM d1_user)\nWHERE g.start_time >= now() - INTERVAL 7 DAY\n    AND g.ip_hash = '\u003CIP_HASH_HERE>'\n    AND g.user_id NOT IN ('undefined', '')\nGROUP BY g.user_id, u.github_username, u.email\nORDER BY pack_spend DESC\n```\n\n## 4. Score Distribution (Overview)\n\n```sql\nSELECT\n    multiIf(abuse_score >= 90, '90-100 definite',\n            abuse_score >= 70, '70-89 likely',\n            abuse_score >= 40, '40-69 suspicious',\n            abuse_score >= 10, '10-39 low_risk',\n            '0-9 clean') as bucket,\n    count() as users,\n    round(sum(total_spend), 2) as spend,\n    sum(total_reqs) as requests\nFROM ( \u002F* ... full scoring subquery from #1 ... *\u002F )\nGROUP BY bucket\nORDER BY bucket DESC\n```\n\n## 5. Extract User IDs for Banning\n\n```sql\nSELECT user_id\nFROM ( \u002F* ... full scoring subquery from #1 ... *\u002F )\nWHERE abuse_score >= 90\n```\n\n---\n\n# Known False Positive Patterns\n\n**Always check before banning:**\n\n| Pattern | Why it's a false positive | How to detect |\n|---------|--------------------------|---------------|\n| **Cloudflare WARP\u002FWorkers** | IPv6 `2a06:98c0:3600::` — legit users behind Cloudflare | Check `ip_subnet` starts with `2a06:98c0` |\n| **VPN\u002Fproxy clusters** | Multiple real users behind same VPN exit | Check if cluster has paying users with real emails |\n| **Chinese CGNAT** | Mobile carriers (China Mobile\u002FUnicom\u002FTelecom) share IPs via NAT | Cross-reference with email pattern + spend |\n| **Free balance usage** | Accounts show small \"spend\" from non-pack balance, not real payment | Check `pack_spend` — only pack spend is real payment |\n| **High NSFW, legit user** | Some paying users generate NSFW content legitimately | Check pack spend > $5 — real customers |\n\n**Safe to ban (high confidence):**\n- Zero pack spend + 95%+ error rate + 1000+ requests\u002Fweek\n- Score >= 90 + hotmail\u002Foutlook random email + zero pack spend\n- Score >= 70 + IP cluster >= 100 + zero pack spend\n- Disposable email (hotmail\u002Foutlook\u002Fproton\u002Fqq\u002Fmail.ru\u002Fvk.com\u002Fanonaddy\u002Fanondrop\u002Frambler\u002Fgmx\u002Fyandex) + error >= 95% + $0 pack spend\n- 100% error rate + $0 pack spend (zero successful requests ever)\n- 99%+ error rate + 1000+ requests\u002Fweek (hammering)\n- Multi-account cluster (same email root, e.g. `reksely`\u002F`notreksely`\u002F`rekselicha`)\n\n**Needs review:**\n- Any account with pack spend > $2 (could be real customer)\n- Accounts on Cloudflare IPs (`2a06:98c0:*`)\n- Accounts with real-looking Gmail addresses\n- Accounts with 90-95% error rate but some successful pack spend (may be bad integration, not abuse)\n\n---\n\n# Banning Users\n\n## How Banning Works\n\nThe ban system uses **Better Auth** fields on the `user` table in Cloudflare D1:\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `banned` | boolean (integer 0\u002F1) | Set to `1` to ban |\n| `ban_reason` | text | Shown in 403 error response |\n| `ban_expires` | integer (epoch ms) | `NULL` for permanent, epoch ms for temporary |\n\n**Enforcement** (`src\u002Fmiddleware\u002Fauth.ts`):\n- `assertNotBanned()` runs on every authenticated request (session + API key)\n- If `banned = 1` and not expired → HTTP 403 with ban reason\n- If `ban_expires` is set and has passed → ban is automatically lifted\n\n**There is no admin API for banning** — use `wrangler d1 execute` directly.\n\n## Ban Commands\n\n```bash\n# Single user ban (from enter.pollinations.ai\u002F directory)\nnpx wrangler d1 execute production-pollinations-enter-db --remote \\\n  --command \"UPDATE user SET banned = 1, ban_reason = 'Bot farm abuse' WHERE id = '\u003CUSER_ID>'\"\n\n# Batch ban (from a file of user IDs, one per line)\nIDS=$(cat user_ids_to_ban.txt | sed \"s\u002F^\u002F'\u002F;s\u002F$\u002F'\u002F\" | paste -sd, -)\nnpx wrangler d1 execute production-pollinations-enter-db --remote \\\n  --command \"UPDATE user SET banned = 1, ban_reason = 'Automated: bot farm abuse' WHERE id IN ($IDS)\"\n\n# Unban a user (if false positive)\nnpx wrangler d1 execute production-pollinations-enter-db --remote \\\n  --command \"UPDATE user SET banned = 0, ban_reason = NULL WHERE id = '\u003CUSER_ID>'\"\n\n# Temporary ban (expires after 7 days)\nnpx wrangler d1 execute production-pollinations-enter-db --remote \\\n  --command \"UPDATE user SET banned = 1, ban_reason = 'Temporary: rate abuse', ban_expires = $(date -v+7d +%s)000 WHERE id = '\u003CUSER_ID>'\"\n```\n\n**D1 database names:**\n- Production: `production-pollinations-enter-db`\n- Staging: `staging-pollinations-enter-db`\n- Development: `development-pollinations-enter-db`\n\n---\n\n# Abuse Profile: Chinese Bot Farm (March 2026)\n\n**Characteristics discovered:**\n- **Scale**: 234+ accounts, 6.4M requests\u002Fweek (23% of all traffic)\n- **IPs**: Chinese residential ISPs (China Telecom, Unicom, Mobile) — 60+ distinct IPs per user across 50+ subnets\n- **Emails**: Random strings at hotmail.com\u002Foutlook.com\u002Fproton.me (e.g., `lhanbqkf6005@hotmail.com`)\n- **Usernames**: Gibberish GitHub usernames (e.g., `bomteupted-bsfo`, `jwolfwersenmroom`)\n- **Behavior**: 100% image generation, 100% error rate, 100% NSFW moderation flags\n- **Spend**: $0 pack spend (small non-pack balance usage at most)\n- **Account age**: All created within days of each other (Feb 2026)\n\n---\n\n# Data Sources\n\n| Table | Key columns for abuse |\n|-------|----------------------|\n| `generation_event_v2` | `user_id`, `ip_hash`, `ip_subnet`, `response_status`, `total_price`, `selected_meter_slug`, `moderation_prompt_*`, `event_type` |\n| `d1_user` | `id`, `email`, `github_username`, `banned`, `banReason`, `created_at` |\n\n**IP implementation** (`src\u002Fmiddleware\u002Ftrack.ts`):\n- `ip_hash`: Salted SHA-256 of full IP (irreversible)\n- `ip_subnet`: Truncated to \u002F24 (IPv4) or \u002F48 (IPv6)\n- Source: `cf-connecting-ip` header\n\n---\n\n# Action Log\n\n| Date | Action | Count | Details |\n|------|--------|-------|---------|\n| 2026-03-06 | Banned bot farm | 277 | IP cluster ≥100, 95%+ errors, $0 pack spend |\n| 2026-03-06 | Rate-limited bot farm | 42 | Same bot farm, no pack spend |\n| 2026-03-06 | Rate-limited bot farm | 59 | Multi-signal: IP clusters, gibberish suffixes, disposable emails, hammering |\n\n---\n\n# Notes\n\n- **IP coverage**: Started 2026-03-06, ~19% user coverage initially. Re-run analysis as coverage grows.\n- **d1_user sync lag**: The `d1_user` table in Tinybird syncs periodically (not real-time). After banning on D1, Tinybird data is stale — verify actions on D1 directly.\n- **Pack spend is the strongest payment signal** for abuse review. Total generation spend can include non-pack balance-bucket usage, so filter on `pack_spend` to catch accounts with no real payment.\n- **Gibberish suffix usernames**: Bot farms use GitHub usernames with suffixes like `-boop`, `-a11y`, `-max`, `-sudo`, `-cmd`, `-stack`, `-pixel`, `-dot`, `-beep`, `-commits`, `-ops`, `-dotcom`, `-lang`, `-bit`. These are auto-generated.\n- Consider adding: account age signal, GitHub account age, user-agent clustering\n",{"name":5,"description":7},"wan-aspect-ratio-fix","0cf9c44b2cb868c1431babf98007a269e7a2b66b",".claude\u002Fskills\u002Fabuse-detection","https:\u002F\u002Fgithub.com\u002FAPPLEPIE6969\u002FPollinations","https:\u002F\u002Fgithub.com\u002FAPPLEPIE6969","2026-07-26 00:50:46",{"source":8,"skillName":5,"commands":48,"prompt":58,"zipAvailable":59},[49,52,55],{"tool":50,"command":51},"npx","npx skills add APPLEPIE6969\u002FPollinations --skill abuse-detection",{"tool":53,"command":54},"bunx","bunx skills add APPLEPIE6969\u002FPollinations --skill abuse-detection",{"tool":56,"command":57},"pnpm","pnpm dlx skills add APPLEPIE6969\u002FPollinations --skill abuse-detection","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FAPPLEPIE6969\u002FPollinations\u002Fblob\u002Fwan-aspect-ratio-fix\u002F.claude\u002Fskills\u002Fabuse-detection\u002FSKILL.md",true,[],[62,95,116,140,163,178],{"skillNo":63,"name":64,"nameZh":6,"description":65,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":66,"categories":67,"keywords":76,"publishedAt":36},"01M6R5KBQ6ARHS4YP4XZX06DJC","polli","Generate images, text, audio, video, and transcribe speech via the Pollinations API using the polli CLI. Use when asked to generate media, call pollinations.ai, check pollen balance, list models, manage API keys, inspect quests, manage my-models, or run polli commands.","https:\u002F\u002Fgithub.com\u002FAPPLEPIE6969\u002FPollinations\u002Fblob\u002Fwan-aspect-ratio-fix\u002Fpackages\u002Fpolli-cli\u002FSKILL.md",[68,73],{"categoryNo":69,"categoryName":70,"taxonomyType":71,"taxonomyTypeDesc":72},"01JBSEEDCAT000000000000010","后端与接口","SCENARIO","使用场景",{"categoryNo":74,"categoryName":75,"taxonomyType":71,"taxonomyTypeDesc":72},"01JBSEEDCAT000000000000016","图像与多媒体",[64,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,21],"cli","generate","run","speech","api","Video","Media","Audio","Bash","text","list","images","commands","balance","quests","my","inspect","api keys",{"skillNo":96,"name":97,"nameZh":6,"description":98,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":99,"categories":100,"keywords":101,"publishedAt":36},"01M6R5K5FEQFK9BRNY2S06M73S","founder-meditation","When something goes wrong — build failures, crashes, errors, test failures, deployment issues — generate a short calming meditation with TTS audio to reassure the user that everything will be okay.","https:\u002F\u002Fgithub.com\u002FAPPLEPIE6969\u002FPollinations\u002Fblob\u002Fwan-aspect-ratio-fix\u002Fapps\u002Fopenclaw\u002Fskills\u002Ffounder-meditation\u002FSKILL.md",[],[102,103,104,105,78,106,107,81,84,85,108,109,110,111,112,31,113,114,115,21],"founder","founder meditation","test","deployment","issues","https","tts","curl","short","user","build","with","errors","Wrong",{"skillNo":117,"name":118,"nameZh":6,"description":119,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":120,"categories":121,"keywords":125,"publishedAt":36},"01M6R5JT4Q4B2SE36ZP416AJ4Q","web-research","Query Pollinations text API with web-search models (gemini-search, perplexity-fast, nomnom, etc.). Use when you need web search grounded answers via Pollinations.","https:\u002F\u002Fgithub.com\u002FAPPLEPIE6969\u002FPollinations\u002Fblob\u002Fwan-aspect-ratio-fix\u002F.claude\u002Fskills\u002Fweb-research\u002FSKILL.md",[122],{"categoryNo":123,"categoryName":124,"taxonomyType":71,"taxonomyTypeDesc":72},"01JBSEEDCAT000000000000021","资料检索与研究",[126,127,128,129,130,131,132,81,133,86,32,134,31,135,136,137,113,138,139,21],"research","web","web research","gemini","search","fast","perplexity","web search","models","web-search","query","via","you","nomnom",{"skillNo":141,"name":142,"nameZh":6,"description":143,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":144,"categories":145,"keywords":146,"publishedAt":36},"01M6R5JMK3CJN4VEKVX23745BR","voting-status","Create and post ASCII art voting status diagrams to GitHub issues and Discord. Use when asked to update voting, show voting results, or announce voting status.","https:\u002F\u002Fgithub.com\u002FAPPLEPIE6969\u002FPollinations\u002Fblob\u002Fwan-aspect-ratio-fix\u002F.claude\u002Fskills\u002Fvoting-status\u002FSKILL.md",[],[147,148,149,150,151,152,153,154,106,155,32,156,157,158,159,160,161,162,21],"status","voting","voting status","discord","github","create","update","github issues","results","ascii art","diagrams","Art","show","ascii","post","announce",{"skillNo":164,"name":165,"nameZh":6,"description":166,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":167,"categories":168,"keywords":172,"publishedAt":36},"01M6R5J6ZK52VS1783EJH36137","tinybird-deploy","Deploy Tinybird pipes and datasources for enter.pollinations.ai observability with the Tinybird Forward CLI.","https:\u002F\u002Fgithub.com\u002FAPPLEPIE6969\u002FPollinations\u002Fblob\u002Fwan-aspect-ratio-fix\u002F.claude\u002Fskills\u002Ftinybird-deploy\u002FSKILL.md",[169],{"categoryNo":170,"categoryName":171,"taxonomyType":71,"taxonomyTypeDesc":72},"01JBSEEDCAT000000000000011","运维与部署",[173,174,175,77,176,31,113,177],"deploy","tinybird","tinybird deploy","observability","for",{"skillNo":179,"name":180,"nameZh":6,"description":181,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":182,"categories":183,"keywords":184,"publishedAt":36},"01M6R5HYNSNJBPMC3SQ7PZVM5Y","sync-production","Sync the main branch into production via the GitHub merges API. Pre-checks for merge conflicts and bails out with a clear reason if the merge isn't clean. Use when asked to merge main into production, deploy main to production, or sync production.","https:\u002F\u002Fgithub.com\u002FAPPLEPIE6969\u002FPollinations\u002Fblob\u002Fwan-aspect-ratio-fix\u002F.claude\u002Fskills\u002Fsync-production\u002FSKILL.md",[],[185,186,187,151,188,173,81,189,32,190,191,192,193,194,137,113,177,195,21],"sync","Production","sync production","merge","branch","merge conflicts","conflicts","clean","main","clear","reason"]