Skip to content

Commit 667657c

Browse files
committed
Define field limit for username, email and root directory #223
1 parent 5ac38b2 commit 667657c

File tree

7 files changed

+76
-10
lines changed

7 files changed

+76
-10
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,26 +107,29 @@ Professional support for Rdiffweb is available by contacting [IKUS Soft](https:/
107107

108108
# Changelog
109109

110-
## 2.4.8 (2022-09-23)
110+
## 2.4.8 (2022-09-24)
111111

112112
This releases include a security fix. If you are using an earlier version, you should upgrade to this release immediately.
113113

114114
* Clean-up invalid path on error page
115+
* Limit username field length [CVE-2022-3290](https://nvd.nist.gov/vuln/detail/CVE-2022-3290)
116+
* Limit user's email field length [CVE-2022-3272](https://nvd.nist.gov/vuln/detail/CVE-2022-3272)
117+
* Limit user's root directory field length [CVE-2022-3295](https://nvd.nist.gov/vuln/detail/CVE-2022-3295)
115118

116119
## 2.4.7 (2002-09-21)
117120

118121
This releases include a security fix. If you are using an earlier version, you should upgrade to this release immediately.
119122

120-
* Generate a new session on login and 2FA #220
121-
* Mitigate CSRF on user's settings #221
123+
* Generate a new session on login and 2FA #220 [CVE-2022-3269](https://nvd.nist.gov/vuln/detail/CVE-2022-3269)
124+
* Mitigate CSRF on user's settings #221 [CVE-2022-3274](https://nvd.nist.gov/vuln/detail/CVE-2022-3274)
122125

123126
## 2.4.6 (2022-09-20)
124127

125128
This releases include a security fix. If you are using an earlier version, you should upgrade to this release immediately.
126129

127130
* Support MarkupSafe<3 for Debian bookworm
128131
* Mitigate CSRF on user's notification settings #216 [CVE-2022-3233](https://nvd.nist.gov/vuln/detail/CVE-2022-3233)
129-
* Mitigate CSRF on repository settings #217
132+
* Mitigate CSRF on repository settings #217 [CVE-2022-3267](https://nvd.nist.gov/vuln/detail/CVE-2022-3267)
130133
* Use 'Secure' Attribute with Sensitive Cookie in HTTPS Session on HTTP Error #218 [CVE-2022-3174](https://nvd.nist.gov/vuln/detail/CVE-2022-3174)
131134

132135
## 2.4.5 (2002-09-16)

rdiffweb/controller/page_admin.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
# Define the logger
4242
logger = logging.getLogger(__name__)
4343

44+
# Maximum file path
45+
MAX_PATH = 260
46+
4447

4548
def get_pyinfo():
4649
try:
@@ -166,11 +169,27 @@ def process_formdata(self, valuelist):
166169

167170
class UserForm(CherryForm):
168171
userid = StringField(_('UserID'))
169-
username = StringField(_('Username'), validators=[validators.data_required()])
170-
email = EmailField(_('Email'), validators=[validators.optional()])
172+
username = StringField(
173+
_('Username'),
174+
validators=[
175+
validators.data_required(),
176+
validators.length(max=256, message=_('Username too long.')),
177+
],
178+
)
179+
email = EmailField(
180+
_('Email'),
181+
validators=[
182+
validators.optional(),
183+
validators.length(max=256, message=_('Email too long.')),
184+
],
185+
)
171186
password = PasswordField(_('Password'), validators=[validators.optional()])
172187
user_root = StringField(
173-
_('Root directory'), description=_("Absolute path defining the location of the repositories for this user.")
188+
_('Root directory'),
189+
description=_("Absolute path defining the location of the repositories for this user."),
190+
validators=[
191+
validators.length(max=MAX_PATH, message=_('Root directory too long.')),
192+
],
174193
)
175194
role = SelectField(
176195
_('User Role'),

rdiffweb/controller/page_login.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import cherrypy
2020
from wtforms.fields import PasswordField, StringField
2121
from wtforms.fields.simple import HiddenField
22-
from wtforms.validators import InputRequired
22+
from wtforms.validators import InputRequired, Length
2323

2424
from rdiffweb.controller import Controller, flash
2525
from rdiffweb.controller.cherrypy_wtf import CherryForm
@@ -34,7 +34,7 @@
3434
class LoginForm(CherryForm):
3535
login = StringField(
3636
_('Username'),
37-
validators=[InputRequired()],
37+
validators=[InputRequired(), Length(max=256, message=_('Username too long.'))],
3838
render_kw={
3939
"placeholder": _('Username'),
4040
"autocorrect": "off",

rdiffweb/controller/pref_general.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@
3838

3939

4040
class UserProfileForm(CherryForm):
41-
email = EmailField(_('Email'), validators=[DataRequired(), Regexp(PATTERN_EMAIL, message=_("Invalid email."))])
41+
email = EmailField(
42+
_('Email'),
43+
validators=[
44+
DataRequired(),
45+
Length(max=256, message=_("Invalid email.")),
46+
Regexp(PATTERN_EMAIL, message=_("Invalid email.")),
47+
],
48+
)
4249

4350

4451
class UserPasswordForm(CherryForm):

rdiffweb/controller/tests/test_page_admin.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,33 @@ def test_add_without_user_root(self):
239239
user = self.app.store.get_user('test6')
240240
self.assertEqual('', user.user_root)
241241

242+
def test_add_with_username_too_long(self):
243+
# Given a too long username
244+
username = "test2" * 52
245+
# When trying to create the user
246+
self._add_user(username, None, "password", "/tmp/", USER_ROLE)
247+
# Then an error is raised
248+
self.assertStatus(200)
249+
self.assertInBody("Username too long.")
250+
251+
def test_add_with_email_too_long(self):
252+
# Given a too long username
253+
email = ("test2" * 50) + "@test.com"
254+
# When trying to create the user
255+
self._add_user("test2", email, "password", "/tmp/", USER_ROLE)
256+
# Then an error is raised
257+
self.assertStatus(200)
258+
self.assertInBody("Email too long.")
259+
260+
def test_add_with_user_root_too_long(self):
261+
# Given a too long user root
262+
user_root = "/temp/" * 50
263+
# When trying to create the user
264+
self._add_user("test2", "test@test,com", "password", user_root, USER_ROLE)
265+
# Then an error is raised
266+
self.assertStatus(200)
267+
self.assertInBody("Root directory too long.")
268+
242269
def test_delete_user_with_not_existing_username(self):
243270
"""
244271
Verify failure to delete invalid username.

rdiffweb/controller/tests/test_page_login.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ def test_getpage_without_username(self):
132132
self.getPage('/login/', method='GET')
133133
self.assertStatus('200 OK')
134134

135+
def test_getpage_with_username_too_long(self):
136+
b = {'login': 'admin' * 52, 'password': 'admin123'}
137+
self.getPage('/login/', method='POST', body=b)
138+
self.assertStatus('200 OK')
139+
self.assertInBody('Username too long.')
140+
135141
def test_getpage_with_empty_password(self):
136142
"""
137143
Check if authentication is failing without a password.

rdiffweb/controller/tests/test_page_prefs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ def test_change_email_with_invalid_email(self):
8484
self._set_profile_info("[email protected], [email protected]")
8585
self.assertInBody("Invalid email")
8686

87+
def test_change_email_with_too_long(self):
88+
self._set_profile_info(("test1" * 50) + "@test.com")
89+
self.assertInBody("Invalid email")
90+
8791
def test_change_password(self):
8892
# When udating user's password
8993
self._set_password(self.PASSWORD, "newpassword", "newpassword")

0 commit comments

Comments
 (0)