[Security] Contest problem IDOR (missing ownership check) + SSO token replay + registration race
OnlineJudge — Contest Problem IDOR + SSO Token Replay + Registration Race
This report documents multiple security vulnerabilities in the master branch of OnlineJudge, verified against the current source.
Finding 1 — [HIGH] Contest problem IDOR (missing ownership check)
Location: problem/views/admin.py:471 (AddContestProblemAPI)
AddContestProblemAPI allows any admin to add any problem to any contest without verifying the user is the contest creator. Every other admin endpoint operating on a contest calls ensure_created_by(contest, request.user):
ContestProblemAPI.post/put/delete(L316, L364, L382)TestCaseAPI(L127, L129)ContestAnnouncementAPI, etc.
But AddContestProblemAPI (L471) omits this check entirely. An admin who did not create a contest injects problems into it — disrupting live competitions, leaking private problems, or unbalancing difficulty.
class AddContestProblemAPI(APIView):
@validate_serializer(AddContestProblemSerializer)
# ← NO ensure_created_by(contest, request.user), unlike every sibling endpointSteps:
curl -X POST "http://<host>/api/admin/contest_problem/add/" \
-H "Authorization: Token <admin_B_token>" -H "Content-Type: application/json" \
-d '{"contest_id": <admin_A_contest_id>, "problem_id": <any_problem_id>}'
# problem added to admin A's contest without ownership check.Finding 2 — [HIGH] SSO token replay (not single-use, no expiry)
Location: account/views/oj.py:282-292
The SSO token generated by the GET endpoint is never invalidated after the POST endpoint consumes it. The auth_token persists in the User model with no expiration or consumption flag. After POST validates the token and returns the user's identity (including admin_type), the token remains valid and can be replayed indefinitely — violating the SSO business rule that one-time auth tokens must be consumed on use.
An attacker who intercepts an SSO token (logs, Referer, sniffing) replays it at any later time for full impersonation.
Finding 3 — [HIGH] Registration race → duplicate email
Location: account/views/oj.py:UserRegisterAPI.post
Email uniqueness is checked at the application level (filter().exists()), then the user is created in a separate step. The email field (models.TextField(null=True)) lacks a DB unique constraint (unlike username). Two concurrent registrations with the same email both pass the exists() check before either inserts, yielding two accounts sharing an email. Password-reset (User.objects.get(email__iexact=...)) then raises MultipleObjectsReturned or returns the wrong account — enabling account takeover via password reset.
Suggested fixes
- Add
ensure_created_by(contest, request.user)toAddContestProblemAPI(Finding 1). - Delete/invalidate the SSO
auth_tokenafter the POST consumes it; add an expiry (Finding 2). - Add a DB unique constraint on
email(or useunique=True) and handleIntegrityError(Finding 3).
All findings verified against the master branch source.
Source: QingdaoU/OnlineJudge