Registrierung & Login: - E-Mail-Verifikation jetzt Pflicht vor erstem Login - Register gibt keinen Token mehr zurück → "Postfach prüfen"-Screen - Login blockt mit EMAIL_NOT_VERIFIED (403) wenn unverifiziert - Resend-Verification ohne Auth (email-basiert) - Frontend: _renderVerifyPending() nach Register und Login-Fehler - Account-Lockout: 5 Fehlversuche → 15 Min gesperrt (ratelimit.py) - Login Rate-Limit zusätzlich per E-Mail-Adresse (5/5 Min) - Fehler-Tracking wird bei erfolgreichem Login zurückgesetzt E-Mail-Templates (alle Mails jetzt HTML): - email_html() Shared-Template in mailer.py (Gradient-Header, Warm-Beige) - Verifikations-Mail, Passwort-Reset → HTML mit CTA-Button - Admin-Outreach: plain text auto-wrapped in HTML - Züchter-Mails (Antrag/Genehmigung/Ablehnung) → Template - Tierschutz-Alert (litters.py) → Template - send_support_mail → HTML - outreach._build_message() + _send_smtp() unterstützen jetzt html= Parameter Forum-Schutz: - Post-Cooldown: 30 Sek zwischen beliebigen Posts (DB-Check) - Stunden-Limit: 5 Threads / 20 Antworten pro User/Stunde - Duplikat-Erkennung: gleicher Text in 5 Min blockiert (in-memory) - content_filter.py: Spam-Keywords, URL-Sperre für Accounts < 7 Tage, Sonderzeichen-Ratio-Check Security-Headers: - HSTS: max-age=31536000; includeSubDomains - Content-Security-Policy: frame-ancestors none, base-uri self, … - X-Frame-Options entfernt (CSP frame-ancestors ist moderner) Honeypot-Fallen (13 Scanner-Pfade → 24h IP-Sperre): - /api/admin/users, /api/v1/users, /api/.env, /api/config, /api/setup, /api/install, /api/phpinfo, /api/debug, /api/actuator, /api/swagger, /api/graphql u.a. Quartalsbericht-System: - backend/scripts/generate_reports.py: 6 Sections (Sicherheit, Funktionsumfang, Dateien, Nutzer, Partner, Server) - make reports: generiert alle Berichte aus dem Container, committed - Scheduler: quarterly_report Job (1. Feb/Mai/Aug/Nov 07:00) → vollständige HTML-Mail an ADMIN_EMAIL - quarterly_report erscheint im täglichen Status-Report Admin-Panel: - "Forum & Meldungen" → "Forum"
63 lines
2.3 KiB
Python
63 lines
2.3 KiB
Python
"""BAN YARO — Content-Filter für Spam und Missbrauch im Forum."""
|
|
|
|
import re
|
|
from datetime import datetime, timedelta, timezone
|
|
from fastapi import HTTPException
|
|
|
|
# Offensichtliche Spam-Signale
|
|
_SPAM_KEYWORDS = [
|
|
"casino", "poker", "slots", "jackpot", "sportwetten",
|
|
"viagra", "cialis", "levitra", "pharmacy", "apotheke online",
|
|
"kreditkarte sofort", "kredit ohne schufa", "schnell geld verdienen",
|
|
"passive income", "work from home", "earn money fast",
|
|
"click here", "klick hier", "free followers", "buy followers",
|
|
"whatsapp +", "telegram +", "call now", "jetzt anrufen",
|
|
"seo service", "backlinks kaufen", "website traffic",
|
|
"crypto invest", "bitcoin verdienen", "nft mint",
|
|
"lose weight fast", "abnehmen schnell", "diät pille",
|
|
]
|
|
|
|
# URL-Muster (http/https oder nackte Domains)
|
|
_URL_RE = re.compile(
|
|
r"(https?://|www\.|\b[a-zA-Z0-9-]+\.(de|com|net|org|io|app|shop|info|biz|ru|cn)\b)",
|
|
re.IGNORECASE,
|
|
)
|
|
|
|
# Mindest-Account-Alter für URL-Posts (Tage)
|
|
_MIN_DAYS_FOR_URLS = 7
|
|
|
|
|
|
def check_forum_content(text: str, user_created_at: str | None = None) -> None:
|
|
"""
|
|
Prüft Forum-Text auf Spam.
|
|
Wirft HTTPException(400) bei Fund.
|
|
"""
|
|
lower = text.lower()
|
|
|
|
# Spam-Keywords
|
|
for kw in _SPAM_KEYWORDS:
|
|
if kw in lower:
|
|
raise HTTPException(400, "Dein Beitrag wurde als Spam erkannt und nicht gespeichert.")
|
|
|
|
# URLs in neuen Accounts sperren
|
|
if _URL_RE.search(text):
|
|
if user_created_at:
|
|
try:
|
|
created = datetime.fromisoformat(user_created_at)
|
|
if created.tzinfo is None:
|
|
created = created.replace(tzinfo=timezone.utc)
|
|
age = datetime.now(timezone.utc) - created
|
|
if age < timedelta(days=_MIN_DAYS_FOR_URLS):
|
|
raise HTTPException(
|
|
400,
|
|
"Links können erst nach 7 Tagen Mitgliedschaft gepostet werden."
|
|
)
|
|
except (ValueError, TypeError):
|
|
pass
|
|
|
|
# Zu viele Sonderzeichen / Zeichensalat
|
|
if len(text) > 20:
|
|
alnum = sum(c.isalnum() or c.isspace() for c in text)
|
|
ratio = alnum / len(text)
|
|
if ratio < 0.5:
|
|
raise HTTPException(400, "Dein Beitrag enthält zu viele Sonderzeichen.")
|