Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(auth): temporarily disable abusive users

yushen49cc7d6f4660
diff --git a/server/internal/auth/temporary_disabled_users.go b/server/internal/auth/temporary_disabled_users.go
new file mode 100644
index 0000000000..cc94b64bac
--- /dev/null
+++ b/server/internal/auth/temporary_disabled_users.go
@@ -0,0 +1,44 @@
+package auth
+
+import (
+ "errors"
+ "strings"
+)
+
+const TemporarilyDisabledUserError = "account disabled"
+
+var ErrTemporarilyDisabledUser = errors.New(TemporarilyDisabledUserError)
+
+// Temporary emergency denylist. Remove this once account suspension is
+// persisted and enforced from the user model.
+var temporarilyDisabledUserIDs = map[string]struct{}{
+ "514492f7-b30f-4147-bd33-c0e8ce5d6d4f": {},
+ "1d542296-17c6-484a-9914-dcee589be116": {},
+}
+
+var temporarilyDisabledUserEmails = map[string]struct{}{
+}
+
+func IsTemporarilyDisabledUser(userID, email string) bool {
+ return IsTemporarilyDisabledUserID(userID) || IsTemporarilyDisabledUserEmail(email)
+}
+
+func IsTemporarilyDisabledUserID(userID string) bool {
+ userID = strings.ToLower(strings.TrimSpace(userID))
+ if userID == "" {
+ return false
+ }
+ _, ok := temporarilyDisabledUserIDs[userID]
+ return ok
+}
+
+func IsTemporarilyDisabledUserEmail(email string) bool {
+ email = strings.ToLower(strings.TrimSpace(email))
+ if email == "" {
+ return false
+ }
+ _, ok := temporarilyDisabledUserEmails[email]
+ return ok
+}
diff --git a/server/internal/handler/auth.go b/server/internal/handler/auth.go
index 585a17b68f..3832fdb17f 100644
--- a/server/internal/handler/auth.go
+++ b/server/internal/handler/auth.go
@@ -150,6 +150,9 @@ func isSixDigitCode(code string) bool {
}
func (h *Handler) issueJWT(user db.User) (string, error) {
+ if auth.IsTemporarilyDisabledUser(uuidToString(user.ID), user.Email) {
+ return "", auth.ErrTemporarilyDisabledUser
+ }
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
"sub": uuidToString(user.ID),
"email": user.Email,
@@ -165,11 +168,18 @@ func (h *Handler) issueJWT(user db.User) (string, error) {
// event fires on that edge, covering both the verification-code and Google
// OAuth entry points.
func (h *Handler) findOrCreateUser(ctx context.Context, email string) (user db.User, isNew bool, err error) {
+ if auth.IsTemporarilyDisabledUserEmail(email) {
+ return db.User{}, false, auth.ErrTemporarilyDisabledUser
+ }
+
user, err = h.Queries.GetUserByEmail(ctx, email)
isNew = isNotFound(err)
if err != nil && !isNew {
return db.User{}, false, err
}
+ if !isNew && auth.IsTemporarilyDisabledUser(uuidToString(user.ID), user.Email) {
+ return db.User{}, false, auth.ErrTemporarilyDisabledUser
+ }
if err := h.checkSignupAllowed(email, isNew); err != nil {
return db.User{}, false, err
@@ -277,9 +287,13 @@ func (h *Handler) SendCode(w http.ResponseWriter, r *http.Request) {
writeError(w, http.StatusBadRequest, "email is required")
return
}
+ if auth.IsTemporarilyDisabledUserEmail(email) {
+ writeError(w, http.StatusForbidden, auth.TemporarilyDisabledUserError)
+ return
+ }
// Check signup restrictions before sending magic link
- _, err := h.Queries.GetUserByEmail(r.Context(), email)
+ existingUser, err := h.Queries.GetUserByEmail(r.Context(), email)
if err != nil {
if !isNotFound(err) {
// Real database/query error → return 500
@@ -299,6 +313,10 @@ func (h *Handler) SendCode(w http.ResponseWriter, r *http.Request) {
}
} else {
// User already exists → always allowed to login
+ if auth.IsTemporarilyDisabledUser(uuidToString(existingUser.ID), existingUser.Email) {
+ writeError(w, http.StatusForbidden, auth.TemporarilyDisabledUserError)
+ return
+ }
isNewUser := false
if err := h.checkSignupAllowed(email, isNewUser); err != nil {
// This should rarely happen, but handle it anyway
@@ -361,6 +379,10 @@ func (h *Handler) VerifyCode(w http.ResponseWriter, r *http.Request) {
writeError(w, http.StatusBadRequest, "email and code are required")
return
}
+ if auth.IsTemporarilyDisabledUserEmail(email) {
+ writeError(w, http.StatusForbidden, auth.TemporarilyDisabledUserError)
+ return
+ }
dbCode, err := h.Queries.GetLatestVerificationCode(r.Context(), email)
if err != nil {
@@ -382,6 +404,10 @@ func (h *Handler) VerifyCode(w http.ResponseWriter, r *http.Request) {
user, isNew, err := h.findOrCreateUser(r.Context(), email)
if err != nil {
+ if errors.Is(err, auth.ErrTemporarilyDisabledUser) {
+ writeError(w, http.StatusForbidden, auth.TemporarilyDisabledUserError)
+ return
+ }
var signupErr SignupError
if errors.As(err, &signupErr) {
writeError(w, http.StatusForbidden, signupErr.Error())
@@ -396,6 +422,10 @@ func (h *Handler) VerifyCode(w http.ResponseWriter, r *http.Request) {
tokenString, err := h.issueJWT(user)
if err != nil {
+ if errors.Is(err, auth.ErrTemporarilyDisabledUser) {
+ writeError(w, http.StatusForbidden, auth.TemporarilyDisabledUserError)
+ return
+ }
slog.Warn("login failed", append(logger.RequestAttrs(r), "error", err, "email", req.Email)...)
writeError(w, http.StatusInternalServerError, "failed to generate token")
return
@@ -547,9 +577,17 @@ func (h *Handler) GoogleLogin(w http.ResponseWriter, r *http.Request) {
}
email := strings.ToLower(strings.TrimSpace(gUser.Email))
+ if auth.IsTemporarilyDisabledUserEmail(email) {
+ writeError(w, http.StatusForbidden, auth.TemporarilyDisabledUserError)
+ return
+ }
user, isNew, err := h.findOrCreateUser(r.Context(), email)
if err != nil {
+ if errors.Is(err, auth.ErrTemporarilyDisabledUser) {
+ writeError(w, http.StatusForbidden, auth.TemporarilyDisabledUserError)
+ return
+ }
var signupErr SignupError
if errors.As(err, &signupErr) {
writeError(w, http.StatusForbidden, signupErr.Error())
@@ -592,6 +630,10 @@ func (h *Handler) GoogleLogin(w http.ResponseWriter, r *http.Request) {
tokenString, err := h.issueJWT(user)
if err != nil {
+ if errors.Is(err, auth.ErrTemporarilyDisabledUser) {
+ writeError(w, http.StatusForbidden, auth.TemporarilyDisabledUserError)
+ return
+ }
slog.Warn("google login failed", append(logger.RequestAttrs(r), "error", err, "email", email)...)
writeError(w, http.StatusInternalServerError, "failed to generate token")
return
@@ -631,6 +673,10 @@ func (h *Handler) IssueCliToken(w http.ResponseWriter, r *http.Request) {
tokenString, err := h.issueJWT(user)
if err != nil {
+ if errors.Is(err, auth.ErrTemporarilyDisabledUser) {
+ writeError(w, http.StatusForbidden, auth.TemporarilyDisabledUserError)
+ return
+ }
slog.Warn("cli-token: failed to issue JWT", append(logger.RequestAttrs(r), "error", err, "user_id", userID)...)
writeError(w, http.StatusInternalServerError, "failed to generate token")
return
diff --git a/server/internal/middleware/auth.go b/server/internal/middleware/auth.go
index a0ab05c9a0..d447a50a59 100644
--- a/server/internal/middleware/auth.go
+++ b/server/internal/middleware/auth.go
@@ -17,6 +17,20 @@ import (
func uuidToString(u pgtype.UUID) string { return util.UUIDToString(u) }
+func rejectTemporarilyDisabledUser(w http.ResponseWriter, r *http.Request, userID, email, authPath string) bool {
+ if !auth.IsTemporarilyDisabledUser(userID, email) {
+ return false
+ }
+ slog.Warn(
+ "auth: temporarily disabled user rejected",
+ "path", r.URL.Path,
+ "user_id", userID,
+ "auth_path", authPath,
+ )
+ writeError(w, http.StatusForbidden, auth.TemporarilyDisabledUserError)
+ return true
+}
+
// Auth middleware validates JWT tokens or Personal Access Tokens.
// Token sources (in priority order):
// 1. Authorization: Bearer <token> header (PAT or JWT)
@@ -82,7 +96,11 @@ func Auth(queries *db.Queries, patCache *auth.PATCache, cloudPAT *auth.CloudPATV
http.Error(w, `{"error":"invalid token"}`, http.StatusUnauthorized)
return
}
- r.Header.Set("X-User-ID", uuidToString(tt.UserID))
+ userID := uuidToString(tt.UserID)
+ if rejectTemporarilyDisabledUser(w, r, userID, "", "task_token") {
+ return
+ }
+ r.Header.Set("X-User-ID", userID)
r.Header.Set("X-Agent-ID", uuidToString(tt.AgentID))
r.Header.Set("X-Task-ID", uuidToString(tt.TaskID))
r.Header.Set("X-Workspace-ID", uuidToString(tt.WorkspaceID))
@@ -136,6 +154,9 @@ func Auth(queries *db.Queries, patCache *auth.PATCache, cloudPAT *auth.CloudPATV
http.Error(w, `{"error":"cloud pat verifier unavailable"}`, http.StatusServiceUnavailable)
return
}
+ if rejectTemporarilyDisabledUser(w, r, identity.OwnerID, "", "cloud_pat") {
+ return
+ }
r.Header.Set("X-User-ID", identity.OwnerID)
// Tag the auth path so account-level guards (e.g.
// handler.RequireHumanActor on /api/cloud-billing/*)
@@ -162,6 +183,9 @@ func Auth(queries *db.Queries, patCache *auth.PATCache, cloudPAT *auth.CloudPATV
// entry since. Skip the DB SELECT and the last_used_at
// UPDATE — last_used_at is bumped once per TTL window.
if userID, ok := patCache.Get(r.Context(), hash); ok {
+ if rejectTemporarilyDisabledUser(w, r, userID, "", "pat_cache") {
+ return
+ }
r.Header.Set("X-User-ID", userID)
next.ServeHTTP(w, r)
return
@@ -179,6 +203,9 @@ func Auth(queries *db.Queries, patCache *auth.PATCache, cloudPAT *auth.CloudPATV
}
userID := uuidToString(pat.UserID)
+ if rejectTemporarilyDisabledUser(w, r, userID, "", "pat") {
+ return
+ }
r.Header.Set("X-User-ID", userID)
// Clamp cache TTL to the token's remaining lifetime so a
@@ -225,8 +252,12 @@ func Auth(queries *db.Queries, patCache *auth.PATCache, cloudPAT *auth.CloudPATV
http.Error(w, `{"error":"invalid claims"}`, http.StatusUnauthorized)
return
}
+ email, _ := claims["email"].(string)
+ if rejectTemporarilyDisabledUser(w, r, sub, email, "jwt") {
+ return
+ }
r.Header.Set("X-User-ID", sub)
- if email, ok := claims["email"].(string); ok {
+ if email != "" {
r.Header.Set("X-User-Email", email)
}
diff --git a/server/internal/middleware/auth_test.go b/server/internal/middleware/auth_test.go
index 429c09e271..1c6575956c 100644
--- a/server/internal/middleware/auth_test.go
+++ b/server/internal/middleware/auth_test.go
@@ -196,6 +196,45 @@ func TestAuth_ValidToken(t *testing.T) {
}
}
+func TestAuth_TemporarilyDisabledJWTByUserID(t *testing.T) {
+ handler := authMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ t.Fatal("next handler should not be called")
+ }))
+
+ claims := validClaims()
+ claims["sub"] = "514492f7-b30f-4147-bd33-c0e8ce5d6d4f"
+ token := generateToken(claims, auth.JWTSecret())
+
+ req := httptest.NewRequest("GET", "/api/me", nil)
+ req.Header.Set("Authorization", "Bearer "+token)
+ w := httptest.NewRecorder()
+ handler.ServeHTTP(w, req)
+
+ if w.Code != http.StatusForbidden {
+ t.Fatalf("expected 403, got %d: %s", w.Code, w.Body.String())
+ }
+}
+
+func TestAuth_TemporarilyDisabledJWTByEmail(t *testing.T) {
+ handler := authMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ t.Fatal("next handler should not be called")
+ }))
+
+ claims := validClaims()
+ claims["sub"] = "not-the-disabled-id"
+ claims["email"] = "[email protected]"
+ token := generateToken(claims, auth.JWTSecret())
+
+ req := httptest.NewRequest("GET", "/api/me", nil)
+ req.Header.Set("Authorization", "Bearer "+token)
+ w := httptest.NewRecorder()
+ handler.ServeHTTP(w, req)
+
+ if w.Code != http.StatusForbidden {
+ t.Fatalf("expected 403, got %d: %s", w.Code, w.Body.String())
+ }
+}
+
func TestAuth_MissingClaims(t *testing.T) {
handler := authMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
t.Fatal("next handler should not be called")
diff --git a/server/internal/middleware/daemon_auth.go b/server/internal/middleware/daemon_auth.go
index 4b4092028a..cc9646a224 100644
--- a/server/internal/middleware/daemon_auth.go
+++ b/server/internal/middleware/daemon_auth.go
@@ -170,6 +170,9 @@ func DaemonAuth(queries *db.Queries, patCache *auth.PATCache, daemonCache *auth.
writeError(w, http.StatusServiceUnavailable, "cloud pat verifier unavailable")
return
}
+ if rejectTemporarilyDisabledUser(w, r, identity.OwnerID, "", DaemonAuthPathCloudPAT) {
+ return
+ }
r.Header.Set("X-User-ID", identity.OwnerID)
// Mirror the regular Auth middleware: tag the auth
// path so any downstream guard (handler.
@@ -191,6 +194,9 @@ func DaemonAuth(queries *db.Queries, patCache *auth.PATCache, daemonCache *auth.
hash := auth.HashToken(tokenString)
if userID, ok := patCache.Get(r.Context(), hash); ok {
+ if rejectTemporarilyDisabledUser(w, r, userID, "", DaemonAuthPathPAT) {
+ return
+ }
r.Header.Set("X-User-ID", userID)
ctx := context.WithValue(r.Context(), ctxKeyDaemonAuthPath, DaemonAuthPathPAT)
next.ServeHTTP(w, r.WithContext(ctx))
@@ -209,6 +215,9 @@ func DaemonAuth(queries *db.Queries, patCache *auth.PATCache, daemonCache *auth.
}
userID := uuidToString(pat.UserID)
+ if rejectTemporarilyDisabledUser(w, r, userID, "", DaemonAuthPathPAT) {
+ return
+ }
r.Header.Set("X-User-ID", userID)
var expiresAt time.Time
@@ -249,6 +258,10 @@ func DaemonAuth(queries *db.Queries, patCache *auth.PATCache, daemonCache *auth.
writeError(w, http.StatusUnauthorized, "invalid claims")
return
}
+ email, _ := claims["email"].(string)
+ if rejectTemporarilyDisabledUser(w, r, sub, email, DaemonAuthPathJWT) {
+ return
+ }
r.Header.Set("X-User-ID", sub)
ctx := context.WithValue(r.Context(), ctxKeyDaemonAuthPath, DaemonAuthPathJWT)
next.ServeHTTP(w, r.WithContext(ctx))
diff --git a/server/internal/realtime/hub.go b/server/internal/realtime/hub.go
index 1b78721bc1..45bce51c36 100644
--- a/server/internal/realtime/hub.go
+++ b/server/internal/realtime/hub.go
@@ -685,6 +685,9 @@ func authenticateToken(tokenStr string, pr PATResolver, ctx context.Context) (st
if !ok {
return "", `{"error":"invalid token"}`
}
+ if auth.IsTemporarilyDisabledUserID(uid) {
+ return "", `{"error":"account disabled"}`
+ }
return uid, ""
}
@@ -707,6 +710,10 @@ func authenticateToken(tokenStr string, pr PATResolver, ctx context.Context) (st
if !ok || strings.TrimSpace(uid) == "" {
return "", `{"error":"invalid claims"}`
}
+ email, _ := claims["email"].(string)
+ if auth.IsTemporarilyDisabledUser(uid, email) {
+ return "", `{"error":"account disabled"}`
+ }
return uid, ""
}
@@ -786,7 +793,11 @@ func HandleWebSocket(hub *Hub, mc MembershipChecker, pr PATResolver, resolveSlug
if cookie, err := r.Cookie(auth.AuthCookieName); err == nil && cookie.Value != "" {
uid, errMsg := authenticateToken(cookie.Value, pr, r.Context())
if errMsg != "" {
- http.Error(w, errMsg, http.StatusUnauthorized)
+ status := http.StatusUnauthorized
+ if errMsg == `{"error":"account disabled"}` {
+ status = http.StatusForbidden
+ }
+ http.Error(w, errMsg, status)
return
}
if !mc.IsMember(r.Context(), uid, workspaceID) {
diff --git a/server/internal/realtime/hub_test.go b/server/internal/realtime/hub_test.go
index 2ee1c2b118..a1723d790e 100644
--- a/server/internal/realtime/hub_test.go
+++ b/server/internal/realtime/hub_test.go
@@ -30,10 +30,21 @@ func (m *mockMembershipChecker) IsMember(_ context.Context, _, _ string) bool {
}
func makeTestToken(t *testing.T) string {
+ return makeTestTokenForUser(t, testUserID, "")
+}
+
+func makeTestTokenForUser(t *testing.T, userID, email string) string {
t.Helper()
- token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
+ claims := jwt.MapClaims{
"sub": testUserID,
- })
+ }
+ if userID != "" {
+ claims["sub"] = userID
+ }
+ if email != "" {
+ claims["email"] = email
+ }
+ token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
signed, err := token.SignedString(auth.JWTSecret())
if err != nil {
t.Fatalf("failed to sign test JWT: %v", err)
@@ -41,6 +52,37 @@ func makeTestToken(t *testing.T) string {
return signed
}
+type staticPATResolver map[string]string
+
+func (s staticPATResolver) ResolveToken(_ context.Context, token string) (string, bool) {
+ userID, ok := s[token]
+ return userID, ok
+}
+
+func TestAuthenticateTokenRejectsTemporarilyDisabledJWTUser(t *testing.T) {
+ token := makeTestTokenForUser(t, "514492f7-b30f-4147-bd33-c0e8ce5d6d4f", "")
+
+ uid, errMsg := authenticateToken(token, nil, context.Background())
+ if uid != "" {
+ t.Fatalf("expected no user ID, got %q", uid)
+ }
+ if !strings.Contains(errMsg, "account disabled") {
+ t.Fatalf("expected account disabled error, got %q", errMsg)
+ }
+}
+
+func TestAuthenticateTokenRejectsTemporarilyDisabledPATUser(t *testing.T) {
+ uid, errMsg := authenticateToken("mul_disabled", staticPATResolver{
+ "mul_disabled": "1d542296-17c6-484a-9914-dcee589be116",
+ }, context.Background())
+ if uid != "" {
+ t.Fatalf("expected no user ID, got %q", uid)
+ }
+ if !strings.Contains(errMsg, "account disabled") {
+ t.Fatalf("expected account disabled error, got %q", errMsg)
+ }
+}
+
func newTestHub(t *testing.T) (*Hub, *httptest.Server) {
t.Helper()
hub := NewHub()