feat(security): add configurable CORS and origin checks

Add settings for allowed CORS origins and WebSocket origin validation so
deployments can restrict cross-origin access instead of using a global
wildcard policy.

Move CORS handling into the security middleware and update report cache
usage to use the dedicated report package.
This commit is contained in:
Akizon77 committed 2026-06-08 20:45:00 +08:00
1 parent 9d914e70b9
commit 7da616ce4c
31 files changed
+550 -320

No files matched your search

+8
View File
@@ -13,6 +13,7 @@ func UpdateUser(c *gin.Context) {
Name *string `json:"username"`
Password *string `json:"password"`
SsoType *string `json:"sso_type"`
TwoFa string `json:"2fa_code"`
}
if err := c.ShouldBindJSON(&req); err != nil {
api.RespondError(c, 400, "Invalid or missing request body: "+err.Error())
@@ -30,6 +31,13 @@ func UpdateUser(c *gin.Context) {
api.RespondError(c, 400, "Password must be at least 6 characters long")
return
}
if req.Password != nil {
c.Set("2fa_code", req.TwoFa)
if err := api.VerifySensitive2FA(c); err != nil {
api.RespondError(c, 401, err.Error())
return
}
}
if err := accounts.UpdateUser(req.Uuid, req.Name, req.Password, req.SsoType); err != nil {
api.RespondError(c, 500, "Failed to update user: "+err.Error())
return