Skip to content

Commit 7493c1a

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 7493c1a

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_web_server.contest_admin_token is not None
127-
and admin_token != config.contest_web_server.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
@@ -451,6 +451,19 @@ def test_impersonation_overrides_ip_lock(self):
451451
self.assertImpersonationSuccess(ip_address="10.0.0.1")
452452
self.assertImpersonationSuccess(ip_address="10.0.1.1")
453453

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

455468
if __name__ == "__main__":
456469
unittest.main()

0 commit comments

Comments
 (0)