Skip to content

Commit 19f36af

Browse files
Florent Flamentrickerc
Florent Flament
authored andcommitted
Sanitizes authentication methods received in requests.
When a user authenticates against Identity V3 API, he can specify multiple authentication methods. This patch removes duplicates, which could have been used to achieve DoS attacks. Closes-Bug: 1300274 (cherry picked from commit ef868ad) Cherry-pick from https://review.openstack.org/#/c/84425/ Change-Id: I6e60324309baa094a5e54b012fb0fc528fea72ab (cherry picked from commit e364ba5)
1 parent c00e867 commit 19f36af

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

keystone/auth/controllers.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,13 @@ def get_method_names(self):
225225
:returns: list of auth method names
226226
227227
"""
228-
return self.auth['identity']['methods'] or []
228+
# Sanitizes methods received in request's body
229+
# Filters out duplicates, while keeping elements' order.
230+
method_names = []
231+
for method in self.auth['identity']['methods']:
232+
if method not in method_names:
233+
method_names.append(method)
234+
return method_names
229235

230236
def get_method_data(self, method):
231237
"""Get the auth method payload.

keystone/tests/test_v3_auth.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ def test_both_project_and_domain_in_scope(self):
8181
None,
8282
auth_data)
8383

84+
def test_get_method_names_duplicates(self):
85+
auth_data = self.build_authentication_request(
86+
token='test',
87+
user_id='test',
88+
password='test')['auth']
89+
auth_data['identity']['methods'] = ['password', 'token',
90+
'password', 'password']
91+
context = None
92+
auth_info = auth.controllers.AuthInfo(context, auth_data)
93+
self.assertEqual(auth_info.get_method_names(),
94+
['password', 'token'])
95+
8496
def test_get_method_data_invalid_method(self):
8597
auth_data = self.build_authentication_request(
8698
user_id='test',

0 commit comments

Comments
 (0)