3x-ui/web/controller
Bug Fix Bot 0404fce020 fix: comprehensive bug fixes across the codebase
## Critical Fixes

### 1. DATA LOSS: 5 functions discard all other clients when updating one
Functions affected:
- SetClientTelegramUserID
- ToggleClientEnableByEmail
- ResetClientIpLimitByEmail
- ResetClientExpiryTimeByEmail
- ResetClientTrafficLimitByEmail

All five built a `newClients` slice by only appending the client
matching the target email, then replaced the entire client list.
Every other client in the inbound was silently deleted.
Fix: update client in-place with break instead of building new slice.

### 2. DATA LOSS: ResetSettings never deletes user credentials
ResetSettings() called `.Where("1 = 1").Error` instead of
`.Delete(model.User{}).Error`. The reset command did nothing to users.

### 3. SECURITY: WebSocket CheckOrigin allows cross-origin hijacking
The fallback `(originHost == "" || requestHost == "")` accepted
any origin with a missing host component. Removed the fallback and
added proper host normalization for IPv6/ports.

### 4. GRACEFUL SHUTDOWN: Server.Stop() uses cancelled context
s.cancel() was called before s.httpServer.Shutdown(s.ctx), making
the context already-done. Shutdown returned immediately (forced kill)
instead of waiting 10 seconds. Moved s.cancel() to end and used
context.WithTimeout(10s) for shutdown. Same fix applied to sub.go.

## Medium Fixes

### 5. Wrong success messages on error paths (~11 endpoints)
When validation failed, endpoints returned messages like
"inboundUpdateSuccess" alongside the error. Fixed to use
"somethingWentWrong" for all error paths.

### 6. resetAllTraffics/resetAllClientTraffics trigger restart on error
SetToNeedRestart() was called in else branch that ran even on failure.
Restructured to only call after confirming success.

### 7. disableInvalidClients has duplicate unreachable error check
Same "User %s not found" string check was nested twice.
Removed the inner duplicate.

### 8. DelInbound logs uninitialized tag variable
The else branch logged empty tag variable instead of actual inbound id.

### 9. check_cpu_usage.go index-out-of-range panic
cpu.Percent() can return empty slice. Added len(percent) > 0 guard.

### 10. Dead code: cron.Remove(entry) on never-added entry
var entry cron.EntryID defaults to 0; cron.Remove(0) is a no-op.

### 11. checkEmailExistForInbound duplicates checkEmailsExistForClients
Refactored to delegate to existing function instead of reimplementing.
2026-03-28 14:12:49 +08:00
..
api.go API improve security: returns 404 for unauthenticated API requests 2025-09-24 11:29:55 +02:00
base.go docs: add comments for all functions 2025-09-20 09:35:50 +02:00
inbound.go fix: comprehensive bug fixes across the codebase 2026-03-28 14:12:49 +08:00
index.go Add Go code analyzer workflow 2026-03-17 23:01:15 +01:00
server.go Refactor code and fix linter warnings (#3627) 2026-01-05 05:54:56 +01:00
setting.go docs: add comments for all functions 2025-09-20 09:35:50 +02:00
util.go docs: add comments for all functions 2025-09-20 09:35:50 +02:00
websocket.go fix: comprehensive bug fixes across the codebase 2026-03-28 14:12:49 +08:00
xray_setting.go fix security issue 2026-02-09 23:36:10 +01:00
xui.go API improve security: returns 404 for unauthenticated API requests 2025-09-24 11:29:55 +02:00