Skip to content

Commit 9e08cf3

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 f26a257 commit 9e08cf3

2 files changed

Lines changed: 18 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_admin_token is not None
127-
and admin_token != config.contest_admin_token):
126+
if config.contest_admin_token is None:
127+
log_failed_attempt("admin token not configured")
128+
return None, None
129+
130+
if admin_token != config.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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,19 @@ def test_impersonation_overrides_ip_lock(self):
447447
self.assertImpersonationSuccess(ip_address="10.0.0.1")
448448
self.assertImpersonationSuccess(ip_address="10.0.1.1")
449449

450+
def test_impersonation_failure(self):
451+
with patch.object(config, "contest_admin_token", "admin-token"):
452+
_, cookie = validate_login(
453+
self.session, self.contest, self.timestamp, "otheruser",
454+
"", ipaddress.ip_address("10.0.0.2"), "wrong-token")
455+
self.assertIsNone(cookie)
456+
457+
def test_impersonation_no_config(self):
458+
_, cookie = validate_login(
459+
self.session, self.contest, self.timestamp, "otheruser",
460+
"", ipaddress.ip_address("10.0.0.2"), "wrong-token")
461+
self.assertIsNone(cookie)
462+
450463

451464
if __name__ == "__main__":
452465
unittest.main()

0 commit comments

Comments
 (0)