Last active
March 22, 2023 14:18
-
-
Save frostming/dbb514c8ae1e9363039e9df537988812 to your computer and use it in GitHub Desktop.
Flask WTF cookie based CSRF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// npm i js-cookie --save | |
import axios from 'axios' | |
import Cookies from 'js-cookie' | |
const api = axios.create({ | |
headers: { | |
'Content-Type': 'application/json', | |
'X-CSRF-TOKEN': Cookies.get('csrf_token') | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request | |
from flask_wtf import CSRFProtect, generate_csrf | |
app = Flask(__name__) | |
CSRFProtect(app) | |
@app.after_request | |
def inject_csrf_token(response): | |
response.set_cookie('csrf_token', generate_csrf()) | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment