Skip to content

Commit e72e0fc

Browse files
committed
issue2550919 - Anti-bot signup using 4 second delay
Took the code by erik forsberg and massaged it into the core. So this is no longer needed in the tracker. Updated devel and responsive trackers to remove timestamp.py and update input field name. Docs, changes and tests complete. Hopefully these tracker changes won't cause an issue for other tests.
1 parent 31cdd8c commit e72e0fc

File tree

12 files changed

+145
-68
lines changed

12 files changed

+145
-68
lines changed

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ Features:
2222
(Ralf Schlatterbeck)
2323
- issue2550926 - Original author adding a second message shouldn't set
2424
status to 'chatting'. See upgrading.txt for details. (John Rouillard)
25+
- issue2550919 - Anti-bot signup using 4 second delay. New config.ini
26+
param [web] registration_delay must be set to 0 if template
27+
user.register.html is not modified. See upgrading.txt for details.
28+
2529
Fixed:
2630

2731
- issue2550996 - Give better error message when running with -c

doc/upgrading.txt

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Migrating from 1.6.X to 2.0.0
2525

2626
Upgrade tracker's config.ini file
2727
--------------------------------------
28-
Once you have installed the new roundup, use:
28+
Once you have installed the new roundup, use::
2929

3030
roundup-admin -i /path/to/tracker updateconfig newconfig.ini
3131

@@ -41,11 +41,14 @@ Python 3 support
4141
Many of the ``.html`` and ``.py`` files from Roundup that are copied
4242
into tracker directories have changed for Python 3 support. If you
4343
wish to move an existing tracker to Python 3, you need to merge in
44-
those changes. If your tracker uses the ``anydbm`` or ``mysql``
45-
backends, you also need to export the tracker contents using
46-
``roundup-admin export`` running under Python 2, and them import them
47-
using ``roundup-admin import`` running under Python 3, as for a
48-
migration to a different backend. If using the ``sqlite`` backend,
44+
those changes. Also you need to make sure that locally created python
45+
code in the tracker is correct for Python 3.
46+
47+
If your tracker uses the ``anydbm`` or ``mysql`` backends, you also
48+
need to export the tracker contents using ``roundup-admin export``
49+
running under Python 2, and them import them using ``roundup-admin
50+
import`` running under Python 3. This is detailed in the documention
51+
for migrating to a different backend. If using the ``sqlite`` backend,
4952
you do not need to export and import, but need to delete the
5053
``db/otks`` and ``db/sessions`` files when changing Python version.
5154
If using the ``postgresql`` backend, you do not need to export and
@@ -65,6 +68,40 @@ back to using python 2. (Note going back to Python 2 will require
6568
the same steps as moving from 2 to 3 except using Python 3 to perform
6669
the export.)
6770

71+
Rate Limit New User Registration
72+
--------------------------------
73+
74+
The new user registration form can be abused by bots to allow
75+
automated registration for spamming. This can be limited by using the
76+
new ``config.ini`` ``[web]`` option called
77+
``registration_delay``. The default is 4 and is the number of seconds
78+
between the time the form was generated and the time the form is
79+
processed.
80+
81+
If you do not modify the ``user.register.html`` template in your
82+
tracker's html directory, you *must* set this to 0. Otherwise you will
83+
see the error:
84+
85+
Form is corrupted, missing: opaqueregister.
86+
87+
If set to 0, the rate limit check is disabled.
88+
89+
If you want to use this, you can change your ``user.register.html``
90+
file to include::
91+
92+
<input type="hidden" name="opaqueregister" tal:attributes="value python: utils.timestamp()">
93+
94+
The hidden input field can be placed right after the form declaration
95+
that starts with::
96+
97+
<form method="POST" onSubmit="return submit_once()"
98+
99+
If you have applied Erik Forsberg's tracker level patch to implement
100+
(see: https://hg.python.org/tracker/python-dev/rev/83477f735132), you
101+
can back the code out of the tracker. You must change the name of the
102+
field in the html template to ``opaqueregistration`` from ``opaque``
103+
in order to use the core code.
104+
68105
PGP mail processing
69106
-------------------
70107

@@ -120,8 +157,8 @@ or::
120157
Update userauditor.py to restrict usernames
121158
-------------------------------------------
122159

123-
A username can be created with embedded commas and &lt; and &gt;
124-
characters. Even though the &lt; and &gt; are usually escaped when
160+
A username can be created with embedded commas and < and >
161+
characters. Even though the < and > are usually escaped when
125162
displayed, the embedded comma makes it difficult to edit lists of
126163
users as they are comma separated.
127164

roundup/cgi/actions.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from roundup.cgi import exceptions, templating
77
from roundup.mailgw import uidFromAddress
88
from roundup.rate_limit import Gcra, RateLimit
9+
from roundup.cgi.timestamp import Timestamped
910
from roundup.exceptions import Reject, RejectRaw
1011
from roundup.anypy import urllib_
1112
from roundup.anypy.strings import StringIO
@@ -1036,7 +1037,7 @@ def handle(self):
10361037
return
10371038
return self.finishRego()
10381039

1039-
class RegisterAction(RegoCommon, EditCommon):
1040+
class RegisterAction(RegoCommon, EditCommon, Timestamped):
10401041
name = 'register'
10411042
permissionType = 'Register'
10421043

@@ -1050,6 +1051,15 @@ def handle(self):
10501051
if self.client.env['REQUEST_METHOD'] != 'POST':
10511052
raise Reject(self._('Invalid request'))
10521053

1054+
# try to make sure user is not a bot by checking the
1055+
# hidden field opaqueregister to make sure it's at least
1056+
# WEB_REGISTRATION_DELAY seconds. If set to 0,
1057+
# disable the check.
1058+
delaytime = self.db.config['WEB_REGISTRATION_DELAY']
1059+
1060+
if delaytime > 0:
1061+
self.timecheck('opaqueregister', delaytime)
1062+
10531063
# parse the props from the form
10541064
try:
10551065
props, links = self.client.parsePropsFromForm(create=1)

roundup/cgi/templating.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
from .KeywordsExpr import render_keywords_expression_editor
3737

38+
from roundup.cgi.timestamp import pack_timestamp
39+
3840
import roundup.anypy.random_ as random_
3941
try:
4042
import cPickle as pickle
@@ -3090,6 +3092,9 @@ def Batch(self, sequence, size, start, end=0, orphan=0, overlap=0):
30903092
def anti_csrf_nonce(self, lifetime=None):
30913093
return anti_csrf_nonce(self.client, lifetime=lifetime)
30923094

3095+
def timestamp(self):
3096+
return pack_timestamp()
3097+
30933098
def url_quote(self, url):
30943099
"""URL-quote the supplied text."""
30953100
return urllib_.quote(url)

share/roundup/templates/classic/html/user.register.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
enctype="multipart/form-data"
1313
tal:attributes="action context/designator">
1414

15+
<input type="hidden" name="opaqueregister"
16+
tal:attributes="value python: utils.timestamp()">
1517
<table class="form">
1618
<tr>
1719
<th i18n:translate="">Name</th>

share/roundup/templates/devel/extensions/timestamp.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

share/roundup/templates/devel/html/user.register.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
enctype="multipart/form-data"
1919
tal:attributes="action context/designator">
2020

21-
<input type="hidden" name="opaque" tal:attributes="value python: utils.timestamp()" />
21+
<input type="hidden" name="opaqueregister"
22+
tal:attributes="value python: utils.timestamp()">
23+
2224
<table class="form">
2325
<tr>
2426
<th i18n:translate="">Name</th>

share/roundup/templates/jinja2/html/user.register.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
name ="itemSynopsis"
1515
enctype ="multipart/form-data"
1616
action ='{{ context.designator() }}'>
17+
<input type="hidden" name="opaqueregister"
18+
value="{{ utils.timestamp() }}" >
1719
<table>
1820
<tr>
1921
<th>{{ i18n.gettext('Name')|u }}</th>

share/roundup/templates/minimal/html/user.register.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
<tal:block tal:condition="editok">
2121
<form method="POST" onSubmit="return submit_once()" enctype="multipart/form-data">
22+
<input type="hidden" name="opaqueregister"
23+
tal:attributes="value python: utils.timestamp()" >
2224
<input type="hidden" name=":template" value="register">
2325
<input type="hidden" name=":required" value="username">
2426
<input type="hidden" name=":required" value="password">

share/roundup/templates/responsive/extensions/timestamp.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)