"feat: Implement CSRF documentation update in backend/app/CSRF_FIX_DOCUMENTATION.md"

This commit is contained in:
2025-05-29 11:54:07 +02:00
parent 3aa05195c0
commit 8e8da1bb07
3 changed files with 31 additions and 3 deletions

View File

@@ -51,6 +51,22 @@ app.config["WTF_CSRF_ENABLED"] = True
csrf = CSRFProtect(app)
# CSRF-Error-Handler
@csrf.error_handler
def csrf_error(reason):
"""Behandelt CSRF-Fehler und gibt detaillierte Informationen zurück."""
app_logger.error(f"CSRF-Fehler für {request.path}: {reason}")
if request.path.startswith('/api/'):
# Für API-Anfragen: JSON-Response
return jsonify({
"error": "CSRF-Token fehlt oder ungültig",
"reason": str(reason),
"help": "Fügen Sie ein gültiges CSRF-Token zu Ihrer Anfrage hinzu"
}), 400
else:
# Für normale Anfragen: Weiterleitung zur Fehlerseite
flash("Sicherheitsfehler: Anfrage wurde abgelehnt. Bitte versuchen Sie es erneut.", "error")
return redirect(request.url)
# Blueprints registrieren
app.register_blueprint(guest_blueprint)