Skip to content

Commit 7c40ee6

Browse files
committed
Fix rate-limit detection
Rate limiting is now based on submitting team, not spoofable submitted team name. Click time recording now updates properly during ban.
1 parent 7b63c84 commit 7c40ee6

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/button.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
db = sqlite3.connect(app_dir + '/../database.db')
1919
#TODO Change this to 1800 for production
2020
time_in_round = 1800
21-
min_time_between_clicks = 1
22-
spam_ban_time = 10
21+
min_time_between_clicks = 2.0 # float seconds
22+
spam_ban_time = 10.0 # float seconds
2323
flag_index = 0
2424

2525
class BaseHandler(tornado.web.RequestHandler):
@@ -51,9 +51,10 @@ def post(self):
5151
raise tornado.web.HTTPError(403)
5252

5353
# is the team being spammy?
54+
user_id = self.get_current_user()
5455
now = time.time()
5556
cursor = db.cursor()
56-
packaged = (team, ) #no idea why you have to do this
57+
packaged = (user_id, ) #no idea why you have to do this
5758
cursor.execute("SELECT * from teams WHERE name=? LIMIT 1", packaged)
5859
row = cursor.fetchone()
5960
if not row:
@@ -65,15 +66,17 @@ def post(self):
6566

6667
if (spamming != 0):
6768
if (since_last_click > spam_ban_time):
68-
self.set_spamming(team, 0)
69+
self.set_spamming(user_id, 0)
6970
else:
71+
self.set_click_time(user_id, now)
7072
raise tornado.web.HTTPError(403)
7173
else:
7274
if (since_last_click < min_time_between_clicks):
73-
self.set_spamming(team, 1)
75+
self.set_click_time(user_id, now)
76+
self.set_spamming(user_id, 1)
7477
raise tornado.web.HTTPError(403)
7578

76-
self.set_click_time(team, now)
79+
self.set_click_time(user_id, now)
7780

7881
#check the captcha
7982
captcha_id_int = int(captcha_id)

0 commit comments

Comments
 (0)