diff --git a/store/app.py b/store/app.py index d54bea73..dd99296b 100644 --- a/store/app.py +++ b/store/app.py @@ -5,6 +5,7 @@ import base64 import hashlib import hmac import os +import string import random import urllib import json @@ -186,6 +187,22 @@ def add_to_wishlist(): "wishlist_add.html", locale=get_locale(), user=session.get("user", {}), + csrf_token=None, + successmsg=None, + errormsg=errormsg, + ) + + csrf_token = request.form["csrf_token"] + print(csrf_token) + print(session.get("csrf_token")) + + if csrf_token != session.get("csrf_token"): + errormsg = _("Invalid CSRF token, please refresh the form and try again") + return render_template( + "wishlist_add.html", + locale=get_locale(), + user=session.get("user", {}), + csrf_token=csrf_token, successmsg=None, errormsg=errormsg, ) @@ -227,6 +244,7 @@ def add_to_wishlist(): "wishlist_add.html", locale=get_locale(), user=session.get("user", {}), + csrf_token=csrf_token, successmsg=None, errormsg=errormsg, ) @@ -247,6 +265,7 @@ def add_to_wishlist(): "wishlist_add.html", locale=get_locale(), user=session.get("user", {}), + csrf_token=csrf_token, successmsg=None, errormsg=_( "An entry with the name %(slug) already exists in the wishlist", @@ -280,6 +299,7 @@ def add_to_wishlist(): "wishlist_add.html", locale=get_locale(), user=session.get("user", {}), + csrf_token=csrf_token, successmsg=None, errormsg=errormsg, ) @@ -328,10 +348,14 @@ Proposed by **{session['user']['username']}** successmsg=successmsg, ) else: + letters = string.ascii_lowercase + string.digits + csrf_token = ''.join(random.choice(letters) for i in range(16)) + session["csrf_token"] = csrf_token return render_template( "wishlist_add.html", locale=get_locale(), user=session.get("user", {}), + csrf_token=csrf_token, successmsg=None, errormsg=None, ) diff --git a/store/templates/wishlist_add.html b/store/templates/wishlist_add.html index e91f1746..5c66e9cc 100644 --- a/store/templates/wishlist_add.html +++ b/store/templates/wishlist_add.html @@ -5,7 +5,7 @@ {% block main %}
- {{ _("You must first login to be allowed to submit an app to the wishlist") }} + {{ _("You must first login to be allowed to submit an app to the wishlist") }}
- {{ _("Please check the license of the app your are proposing") }} + {{ _("Please check the license of the app your are proposing") }}
- {{ _("The YunoHost project will only package free/open-source software (with possible case-by-case exceptions for apps which are not-totally-free)") }} + {{ _("The YunoHost project will only package free/open-source software (with possible case-by-case exceptions for apps which are not-totally-free)") }}