Skip to content

Commit 88bce0a

Browse files
committed
Security: Fix checking of admin tokens in CWS
When the login endpoint of the CWS API was called with an admin token, but no admin token was configured, login succeeded. This allowed attackers to impersonate any CWS user in CMS instances with no admin token configured. Thanks to Samet Akıllı <ssametakilli@gmail.com> for reporting the issue.
1 parent 6a28840 commit 88bce0a

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

cms/server/contest/authentication.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,11 @@ def log_failed_attempt(msg, *args):
123123
return None, None
124124

125125
if admin_token != "":
126-
if (config.contest_web_server.contest_admin_token is not None
127-
and admin_token != config.contest_web_server.contest_admin_token):
126+
if config.contest_web_server.contest_admin_token is None:
127+
log_failed_attempt("admin token not configured")
128+
return None, None
129+
130+
if admin_token != config.contest_web_server.contest_admin_token:
128131
log_failed_attempt("invalid admin token")
129132
return None, None
130133

cmstestsuite/unit_tests/server/contest/authentication_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ def test_successful_impersonation(self):
165165
def test_unsuccessful_impersonation(self):
166166
self.assertFailure("myuser", "", "127.0.0.1", "bad-admin-token")
167167

168+
def test_impersonation_with_no_config(self):
169+
with patch.object(config.contest_web_server, "contest_admin_token", None):
170+
self.assertFailure("myuser", "", "127.0.0.1", "admin-token")
171+
168172
def test_impersonation_overrides_unallowed_password_authentication(self):
169173
self.contest.allow_password_authentication = False
170174

0 commit comments

Comments
 (0)