There was an error while loading. Please reload this page.
1 parent 39ee9d0 commit 01113a8Copy full SHA for 01113a8
1 file changed
app.py
@@ -672,8 +672,17 @@ def _check_csrf():
672
expected = session.get('csrf_token', '')
673
if not expected or not secrets.compare_digest(str(token), str(expected)):
674
logger.warning(f"CSRF check failed from {request.remote_addr}")
675
+ if request.headers.get('X-Requested-With') == 'fetch' or request.is_json:
676
+ raise _CsrfError()
677
abort(403)
678
679
+class _CsrfError(Exception):
680
+ pass
681
+
682
+@app.errorhandler(_CsrfError)
683
+def _handle_csrf_error(e):
684
+ return jsonify({'ok': False, 'message': 'Session expired - please refresh the page.'}), 403
685
686
def csrf_protect(f):
687
@wraps(f)
688
def decorated(*args, **kwargs):
0 commit comments