"Refactor guest templates and blueprint"
This commit is contained in:
@@ -50,6 +50,36 @@ app.config["WTF_CSRF_ENABLED"] = True
|
||||
# CSRF-Schutz initialisieren
|
||||
csrf = CSRFProtect(app)
|
||||
|
||||
# CSRF-Exemption für Guest-API-Endpunkte
|
||||
@app.before_request
|
||||
def csrf_exempt_for_guest_api():
|
||||
"""Befreit bestimmte API-Endpunkte vom CSRF-Schutz."""
|
||||
if request.endpoint and (
|
||||
request.endpoint.startswith('guest.api_') or
|
||||
request.path.startswith('/api/guest/') or
|
||||
request.path.startswith('/api/jobs/start/')
|
||||
):
|
||||
# CSRF-Schutz für diese Endpunkte deaktivieren
|
||||
csrf._exempt_views.add(request.endpoint)
|
||||
|
||||
# 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)
|
||||
app.register_blueprint(calendar_blueprint)
|
||||
|
Reference in New Issue
Block a user