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 %}

- {{ _("Suggest an application to be added to YunoHost's catalog") }} + {{ _("Suggest an application to be added to YunoHost's catalog") }}

@@ -26,7 +26,7 @@ {% endif %} @@ -34,10 +34,10 @@ @@ -50,28 +50,30 @@ {% endif %} -
- + + + + - + {{ _("Please be concise and focus on what the app does.") }} {{ _("No need to repeat '[App] is ...'. No need to state that it is free/open-source or self-hosted (otherwise it wouldn't be packaged for YunoHost). Avoid marketing stuff like 'the most', or vague properties like 'easy', 'simple', 'lightweight'.") }} - + {{ _("Please *do not* just copy-paste the code repository URL. If the project has no proper website, then leave the field empty.") }} - +