Skip to content

Commit 35590cd

Browse files
committed
Protect register endpoint from some bots
They create users like: hVTSSkcQDfprXpJkMFcR TyfUqQmWOWuIudYjn alzAAHhzbxcUBAdiyupV MumHmKSyNTYYwCybOJ JaLujCDdPfvXIYWXhioZqa KgnlfrgUOqNqVAbRiurUeb
1 parent ca8aadb commit 35590cd

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

back/app_flask.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import ics
1717
import markdown
1818
import datetime
19+
import requests
1920

2021
# ------------------------------
2122
# Our helpers
@@ -353,6 +354,13 @@ def logout():
353354
def register():
354355
"""Register an account"""
355356
if request.method == 'POST':
357+
358+
if settings.country_check != '':
359+
# anti bots
360+
r = requests.get(f"http://ip-api.com/json/{request.remote_addr}")
361+
if r.status_code == 200 and r.json()['country'] != settings.country_check:
362+
return "Blocked", 403
363+
356364
httpcode, result, opts = createUser(request.form)
357365
if httpcode == 201:
358366
f = request.form

back/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ mailjet_rest==1.3.4
99
Markdown~=3.8.0
1010
ics==0.7.2
1111
gunicorn==23.0.0
12-
PyYAML==6.0.2
12+
PyYAML==6.0.2
13+
requests==2.32.5

back/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
backgrounds_folder = 'backgrounds'
3838
uploads_allowed_extensions = {'png', 'jpg', 'jpeg', 'gif'}
3939
international_prefix = '+33'
40+
country_check = 'France'
4041
temporary_user_duration = datetime.timedelta(days=60) # +web_remember_JWT_ACCESS_TOKEN_EXPIRES if user checked remember credentials
4142
domain = "https://calendrier.lyonparapente.fr"
4243
emails = {

last_release.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* Fix problem in change_password when not logged in (regression in 78b0031623e19c5b0ae1899ea83ce4a5808a2343)
1+
* Protect register endpoint from some bots

0 commit comments

Comments
 (0)