Skip to content

Commit 361f1e2

Browse files
committed
issue2550919 - Anti-bot signup using 4 second delay
Oops another missing file 8-/.
1 parent e087f35 commit 361f1e2

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

roundup/cgi/timestamp.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'''Set of functions of adding/checking timestamp to be used to limit
2+
form submission for cgi actions.
3+
'''
4+
5+
import time, struct, binascii, base64
6+
from roundup.cgi.exceptions import FormError
7+
from roundup.i18n import _
8+
from roundup.anypy.strings import b2s, s2b
9+
10+
def pack_timestamp():
11+
return b2s(base64.b64encode(struct.pack("i", int(time.time()))).strip())
12+
13+
def unpack_timestamp(s):
14+
try:
15+
timestamp = struct.unpack("i",base64.b64decode(s2b(s)))[0]
16+
except (struct.error, binascii.Error, TypeError) as e:
17+
raise FormError(_("Form is corrupted."))
18+
return timestamp
19+
20+
class Timestamped:
21+
def timecheck(self,field,delay):
22+
try:
23+
created = unpack_timestamp(self.form[field].value)
24+
except KeyError:
25+
raise FormError(_("Form is corrupted, missing: %s."%field))
26+
if time.time() - created < delay:
27+
raise FormError(_("Responding to form too quickly."))
28+
return True

0 commit comments

Comments
 (0)