Skip to content

security: enforce disabled account check in auth middleware#268

Merged
dkhalife merged 1 commit intomainfrom
disabled_account
Mar 26, 2026
Merged

security: enforce disabled account check in auth middleware#268
dkhalife merged 1 commit intomainfrom
disabled_account

Conversation

@dkhalife
Copy link
Copy Markdown
Owner

Problem

The \User.Disabled\ field existed in the DB schema but was never checked during authentication. A disabled user could authenticate and access all HTTP and WebSocket endpoints.

Root Cause

\�erifyAccessToken(), \VerifyWSToken(), and \�ypassAuth()\ all call \EnsureUser()\ but the returned user's \Disabled\ field was never inspected.

Fix

*\�piserver/internal/repos/user/user.go*

  • Added exported sentinel \ErrDisabledUser\
  • \EnsureUser()\ now returns \ErrDisabledUser\ when the fetched user has \Disabled = true\

This single change covers all three auth paths (HTTP, WebSocket, dev bypass) since they all flow through \EnsureUser(). The middleware already propagates errors as \401 Unauthorized, so no middleware changes were needed.

*\�piserver/internal/repos/user/user_test.go*

  • Added \TestEnsureUserDisabled\ to verify a disabled user is rejected with \ErrDisabledUser\

Testing

All 12 existing + new tests pass (\go test ./...).

Copilot AI review requested due to automatic review settings March 26, 2026 02:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR closes a security gap in the Go API server by enforcing the User.Disabled flag during identity resolution, preventing disabled accounts from authenticating across HTTP and WebSocket entrypoints (and the dev auth bypass) that rely on EnsureUser().

Changes:

  • Add exported sentinel ErrDisabledUser in the user repo package.
  • Update EnsureUser() to reject existing users with Disabled=true.
  • Add a unit test verifying EnsureUser() returns ErrDisabledUser for disabled accounts.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
apiserver/internal/repos/user/user.go Introduces ErrDisabledUser and blocks EnsureUser() from returning a disabled user.
apiserver/internal/repos/user/user_test.go Adds coverage to ensure disabled users are rejected with the sentinel error.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@dkhalife dkhalife merged commit 83d9de4 into main Mar 26, 2026
11 checks passed
@dkhalife dkhalife deleted the disabled_account branch March 26, 2026 02:27
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