Automated conservative cleanup for Forgejo SEO spam accounts
  • Python 99.7%
  • Dockerfile 0.3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-25 07:19:34 +00:00
forgejo_janitor fix(llm): treat account data as untrusted and skip private content 2026-11-25 10:30:54 +04:00
tests fix(llm): treat account data as untrusted and skip private content 2026-11-25 10:30:54 +04:00
.gitignore Add Forgejo spam janitor 2026-05-23 14:29:46 +04:00
config.example.toml feat: review flagged users with an LLM 2026-11-25 09:50:59 +04:00
docker-compose.example.yml Monitor and quarantine spam content 2026-05-23 15:00:01 +04:00
Dockerfile Add Forgejo spam janitor 2026-05-23 14:29:46 +04:00
pyproject.toml build: limit package discovery to forgejo_janitor 2026-11-25 09:50:59 +04:00
README.md fix(llm): treat account data as untrusted and skip private content 2026-11-25 10:30:54 +04:00

Forgejo Janitor

Automated, conservative cleanup for Forgejo SEO spam accounts.

The janitor scores recently registered users, or users with recent repository/issue/comment activity, using profile, repository, issue, comment, and SSH-key signals. It is dry-run by default and never deletes accounts. Executed actions are limited to:

  • sanitize_profile: clear profile full_name, website, location, and description.
  • restrict_user: set is_restricted = true.
  • prohibit_login: set prohibit_login = true for high-confidence spam only.
  • quarantine_repo: make a spam repository private, archive it, and clear repo metadata.
  • redact_issue: replace spam issue title/body and close/lock the issue.
  • redact_comment: replace spam comment body.

It intentionally does not print raw email addresses. Reports include only email domains.

Members of protected organizations are never scored or acted on. The default protected org is pleroma.

Quick Start

python -m venv .venv
. .venv/bin/activate
pip install -e '.[test]'
pytest

Run a dry scan:

DATABASE_URL='postgresql://forgejo:password@db:5432/forgejo' \
  forgejo-janitor scan --config config.example.toml --output summary

Run with optional bare repository scanning:

DATABASE_URL='postgresql://forgejo:password@db:5432/forgejo' \
  forgejo-janitor scan \
  --config config.example.toml \
  --repo-root /data/git/repositories \
  --output jsonl

Apply planned actions:

DATABASE_URL='postgresql://forgejo:password@db:5432/forgejo' \
  forgejo-janitor run \
  --config config.example.toml \
  --repo-root /data/git/repositories \
  --max-actions 100 \
  --execute

Monitor recent repo/issue/comment activity continuously:

DATABASE_URL='postgresql://forgejo:password@db:5432/forgejo' \
  forgejo-janitor monitor \
  --config config.example.toml \
  --repo-root /data/git/repositories \
  --activity-minutes 5 \
  --interval 60 \
  --max-actions 100 \
  --execute

Omit --execute to keep monitor mode in dry-run mode.

Email Notifications

Pass --notify-email to send an email when actions are planned or applied. Recipients default to active Forgejo admins from the database unless JANITOR_EMAIL_TO is set.

export JANITOR_SMTP_HOST=mail.example
export JANITOR_SMTP_PORT=587
export JANITOR_SMTP_USERNAME=janitor@example
export JANITOR_SMTP_PASSWORD=secret
export JANITOR_EMAIL_FROM=janitor@example
export JANITOR_EMAIL_TO=admin1@example,admin2@example

Set JANITOR_SMTP_STARTTLS=false to disable STARTTLS.

Omit --execute to keep run in dry-run mode.

Docker

Build locally:

docker build -t forgejo-janitor:latest .

Dry-run with Docker:

docker run --rm \
  --network forgejo_default \
  -e DATABASE_URL='postgresql://forgejo:password@db:5432/forgejo' \
  -v /opt/forgejo/volumes/forgejo/git/repositories:/data/git/repositories:ro \
  -v ./config.example.toml:/config/janitor.toml:ro \
  forgejo-janitor:latest scan --config /config/janitor.toml --repo-root /data/git/repositories

Use docker-compose.example.yml as a starting point for a monitor deployment.

Policy

Thresholds and heuristics live in config.example.toml. The default policy is tuned to remove SEO backlink value first and reserve login prohibition/content redaction for high-confidence issue/repository/comment spam.

Known-good automation should be allowlisted by username or email domain. The example allowlists pleroma-ci and pleroma.social.

Organization members that must never be touched should be listed under allowlist.protected_orgs. The example protects all members of the pleroma organization.

LLM Review

With an [llm] section, users that the heuristics flag (score > 0) go to an OpenAI model, and its verdict replaces the score thresholds. Administrators, allowlisted users and protected-org members never reach the model.

[llm]
enabled = true
model = "gpt-6-luna"
prohibit_min_confidence = 0.9
restrict_min_confidence = 0.7
sanitize_min_confidence = 0.7
max_reviews_per_run = 20   # model calls per run; cache hits are free
cache_path = "/var/lib/forgejo-janitor/llm-cache.json"  # optional
timeout_seconds = 60

Set the API key in OPENAI_API_KEY; the janitor refuses to start with enabled = true and no key. The key is never read from the config file. With enabled = true, a dry-run scan also calls the API and needs the key.

The model sees the user the way an admin does. Full profile data and content go to OpenAI: all profile fields, every email address of the user (with activation state), last login, visibility, counts, public repositories (description, website, empty flag and, with --repo-root, the README), the heuristic score and reasons, and the full text of the last 20 issues/PRs and 20 comments in public repositories, with repository and date. Private repositories and their issues and comments are never sent. Each body and README is capped at 20000 characters. The janitor's own reports and emails still show only email domains.

Verdicts map to actions: ham does nothing, sanitize clears the profile (needs sanitize_min_confidence), restrict also restricts the user (needs restrict_min_confidence), prohibit also blocks login and quarantines/redacts spam content (needs prohibit_min_confidence). A verdict below its threshold drops one level (prohibit, restrict, sanitize, ham). The [policy] enable_* flags still apply. If the model call fails, the user gets no actions in that run and a warning goes to stderr. Users over max_reviews_per_run also get no actions and are reviewed in a later run. The repository list is cut to 10 public repos (non-empty first, then newest), and if the whole context passes 200000 characters the oldest comments, then the oldest issues, then READMEs are dropped.

With cache_path, verdicts are stored per user and reused until the data sent to the model changes. Compare heuristic and LLM decisions by running scan with and without enabled = true.

Known limit: content actions (quarantine/redact) still only target content the heuristics flagged. A model-only prohibit blocks login but does not redact anything.

Development

pytest
python -m forgejo_janitor.cli scan --help