Skip to content

Fix empty token auth bypass#331

Merged
MichaelZhao21 merged 4 commits intohackutd:masterfrom
balebbae:fix-empty-token-auth-bypass
Apr 29, 2026
Merged

Fix empty token auth bypass#331
MichaelZhao21 merged 4 commits intohackutd:masterfrom
balebbae:fix-empty-token-auth-bypass

Conversation

@balebbae
Copy link
Copy Markdown
Contributor

Description

Fixes an authentication bypass in the judge Bearer token middleware. models.NewJudge initializes
Token: "", so any judge inserted via CSV import or single-add (server/router/judge.go:64, :1088,
server/funcs/csv.go:62) sits in Mongo with token: "" until they call /judge/login. The middleware
in server/router/middleware.go only checks len(authHeader) < 7, so an Authorization: Bearer
header (literal "Bearer" + one space) passes the format check, slices to an empty token, and
FindJudgeByToken(db, "") runs FindOne({"token": ""}) — matching the first not-yet-logged-in judge
and authenticating the request as them.

Fix:

  • server/router/middleware.go: reject empty token after slicing the Bearer prefix.
  • server/database/judge.go: defense-in-depth — FindJudgeByToken short-circuits on empty token so any
    future caller is safe.

Fixes #[Issue]

Type of Change

Delete options that do not apply:

  • Bug fix (change which fixes an issue)

Is this a breaking change?

  • Yes
  • No

@balebbae balebbae requested a review from MichaelZhao21 April 29, 2026 21:27
Copy link
Copy Markdown
Contributor

@MichaelZhao21 MichaelZhao21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@MichaelZhao21 MichaelZhao21 merged commit 57f7d49 into hackutd:master Apr 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants