FIX bypass csrf for XHR calls
All checks were successful
Build documentation / build (push) Successful in 6m12s
Install and run tests / test (3.10) (push) Successful in 2m4s
Install and run tests / test (3.11) (push) Successful in 2m21s
Install and run tests / test (3.12) (push) Successful in 2m31s
Install and run tests / test (3.13) (push) Successful in 2m24s
Install and run tests / test (3.8) (push) Successful in 2m2s
Install and run tests / test (3.9) (push) Successful in 2m12s
Build documentation / deploy (push) Successful in 2m28s

This commit is contained in:
boyska 2025-04-15 18:13:33 +02:00
parent 3f5823403c
commit 3f2e4a3a6a
2 changed files with 5 additions and 2 deletions

View file

@ -140,7 +140,7 @@ def is_xhr():
@db.route("/add/time/<kind>", methods=["GET", "POST"])
def addtime_kind(kind):
Form, receiver = tuple(forms.get_timeform(kind))
form = Form(csrf_enabled=(not is_xhr()))
form = Form(meta={'csrf': not is_xhr()})
if request.method == "POST":
if form.validate():
data = receiver(form)
@ -175,7 +175,7 @@ def addaudio():
@db.route("/add/audio/<kind>", methods=["GET", "POST"])
def addaudio_kind(kind):
Form, receiver = tuple(forms.get_audioform(kind))
form = Form(csrf_enabled=(not is_xhr()))
form = Form(meta={'csrf': not is_xhr()})
if request.method == "POST":
if form.validate():
data = receiver(form)

View file

@ -6,6 +6,7 @@ from flask import (Blueprint, Flask, abort, current_app, jsonify, redirect,
render_template, request)
from flask_babel import Babel
from flask_bootstrap import Bootstrap
from flask_wtf.csrf import CSRFProtect
from cachelib import SimpleCache
from greenlet import greenlet
@ -185,6 +186,8 @@ def create_app(queue, larigira):
Bootstrap(app)
babel = Babel(app)
babel.init_app(app, locale_selector=babel_get_locale)
csrf = CSRFProtect(app)
csrf.exempt(db)
app.register_blueprint(rpc)
app.register_blueprint(viewui)
app.register_blueprint(db)