I have a question about csrf Cross-site Request Forgery Attacks in flask.
I found a good youtube video. Basically, in the video:
- someone updated someone's email when logged in through a login path/function that updates the email when logged in.
- then someone updates the email when the csrf token isn't there and ends up inserting data from using an HTML file.
In the video, they only show it is needed for logged-in routes.
Do I need it when I am not logged in? Also, do I need csrf protection for a get request? I assume not because nothing is being submitted.
Also, can I have an empty WTForms, and will the code below work?
Example of emptyforms:
forms.py
class EmptyForm(FlaskForm):
pass
routes.py
@app.route('/random_route')
def some_route_function()
if request.method == 'GET' :
form = EmptyForm()
return render_template ( 'random_route.html', form=form )
random_route.html
<form validate="" id="random_route" method="GET">
<!-- Make the secret key work -->
{{form.csrf_token}}
<h1>Random message this is the only thing the form does. </h1>
</form>
I also have a layout.hmtl which contains the html.