<commit_before>from gavel import app
import gavel.utils as utils
from flask import abort, request, session

@app.before_request
def csrf_protect():
    if request.method == "POST":
        token = session.pop('_csrf_token', None)
        if not token or token != request.form.get('_csrf_token'):
            abort(403)

def generate_csrf_token():
    if '_csrf_token' not in session:
        session['_csrf_token'] = utils.gen_secret(32)
    return session['_csrf_token']

app.jinja_env.globals['csrf_token'] = generate_csrf_token<commit_msg>Switch CSRF token from per-request to per-session<commit_after>from gavel import app
import gavel.utils as utils
from flask import abort, request, session

@app.before_request
def csrf_protect():
    if request.method == "POST":
        token = session.get('_csrf_token', None)
        if not token or token != request.form.get('_csrf_token'):
            abort(403)

def generate_csrf_token():
    if '_csrf_token' not in session:
        session['_csrf_token'] = utils.gen_secret(32)
    return session['_csrf_token']

app.jinja_env.globals['csrf_token'] = generate_csrf_token
{'fraction_non_alphanumeric': 0.10892857142857143, 'fraction_numerical': 0.008928571428571428, 'mean_word_length': 4.026905829596412, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2474829', 'n_tokens_mistral': 373, 'n_tokens_neox': 368, 'n_words': 91}