From 0004445a2bce19f7e487f6e9299ae6d98aaf2768 Mon Sep 17 00:00:00 2001 From: HynoR <20227709+HynoR@users.noreply.github.com> Date: Tue, 6 Jan 2026 15:24:07 +0800 Subject: [PATCH 1/2] feat: Implement connection closure handling in security module --- core/utils/security/security.go | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/core/utils/security/security.go b/core/utils/security/security.go index ea7d6d834dd0..fd3e8a94200d 100644 --- a/core/utils/security/security.go +++ b/core/utils/security/security.go @@ -3,6 +3,11 @@ package security import ( "encoding/base64" "fmt" + "net/http" + "regexp" + "strconv" + "strings" + "github.com/1Panel-dev/1Panel/core/app/repo" "github.com/1Panel-dev/1Panel/core/app/service" "github.com/1Panel-dev/1Panel/core/cmd/server/res" @@ -11,10 +16,6 @@ import ( "github.com/1Panel-dev/1Panel/core/global" "github.com/1Panel-dev/1Panel/core/utils/common" "github.com/gin-gonic/gin" - "net/http" - "regexp" - "strconv" - "strings" ) func HandleNotRoute(c *gin.Context) bool { @@ -98,7 +99,7 @@ func HandleNotSecurity(c *gin.Context, resType string) { return } if resPage == "444" { - c.String(444, "") + closeConn(c) return } @@ -183,3 +184,19 @@ func checkSession(c *gin.Context) bool { _, err := global.SESSION.Get(c) return err == nil } + +func closeConn(c *gin.Context) { + hijacker, ok := c.Writer.(http.Hijacker) + if !ok { + c.AbortWithStatus(http.StatusForbidden) + return + } + conn, _, err := hijacker.Hijack() + if err != nil { + c.AbortWithStatus(http.StatusForbidden) + return + } + + conn.Close() + c.Abort() +} From 64d488b7baf19217fc560086e89a8d2077c16f23 Mon Sep 17 00:00:00 2001 From: HynoR <20227709+HynoR@users.noreply.github.com> Date: Tue, 6 Jan 2026 15:30:12 +0800 Subject: [PATCH 2/2] refactor: Rename closeConn to CloseDirectly for clarity in security module --- core/utils/security/security.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/utils/security/security.go b/core/utils/security/security.go index fd3e8a94200d..c5530ac07127 100644 --- a/core/utils/security/security.go +++ b/core/utils/security/security.go @@ -99,7 +99,7 @@ func HandleNotSecurity(c *gin.Context, resType string) { return } if resPage == "444" { - closeConn(c) + CloseDirectly(c) return } @@ -185,7 +185,7 @@ func checkSession(c *gin.Context) bool { return err == nil } -func closeConn(c *gin.Context) { +func CloseDirectly(c *gin.Context) { hijacker, ok := c.Writer.(http.Hijacker) if !ok { c.AbortWithStatus(http.StatusForbidden)