fix: 解决证书推送到其他节点报错的问题 (#13065)

This commit is contained in:
CityFun
2026-06-17 15:31:51 +08:00
committed by GitHub
parent 7b74e09d30
commit 7f331f5503
5 changed files with 28 additions and 3 deletions
+2 -1
View File
@@ -3,6 +3,7 @@ package v2
import (
"encoding/base64"
"errors"
"net"
"net/http"
"os"
"path"
@@ -350,7 +351,7 @@ func (b *BaseApi) UpdatePort(c *gin.Context) {
// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFunctions":[],"formatZH":"重载系统 SSL","formatEN":"reload system SSL"}
func (b *BaseApi) ReloadSSL(c *gin.Context) {
clientIP := c.ClientIP()
if clientIP != "127.0.0.1" {
if ip := net.ParseIP(clientIP); ip == nil || !ip.IsLoopback() {
helper.InternalServer(c, errors.New("only localhost can reload ssl"))
return
}
+3
View File
@@ -33,6 +33,9 @@ func CSRFTokenGuard() gin.HandlerFunc {
}
func requiresCSRFTokenCheck(c *gin.Context) bool {
if c.GetBool("LOCAL_REQUEST") {
return false
}
unsafeMethod := c.Request.Method != http.MethodGet &&
c.Request.Method != http.MethodHead &&
c.Request.Method != http.MethodOptions &&
+18 -1
View File
@@ -1,6 +1,7 @@
package middleware
import (
"net"
"strings"
"github.com/1Panel-dev/1Panel/core/app/api/v2/helper"
@@ -14,7 +15,7 @@ func WhiteAllow() gin.HandlerFunc {
return func(c *gin.Context) {
tokenString := c.GetHeader("X-Panel-Local-Token")
clientIP := common.GetRealClientIP(c)
if clientIP == "127.0.0.1" && tokenString != "" && c.Request.URL.Path == "/api/v2/core/xpack/sync/ssl" {
if isLocalSyncRequest(c.Request.URL.Path, clientIP, tokenString) {
c.Set("LOCAL_REQUEST", true)
c.Next()
return
@@ -48,3 +49,19 @@ func WhiteAllow() gin.HandlerFunc {
helper.ErrWithHtml(c, code, "err_ip_limit")
}
}
func isLocalSyncRequest(reqPath, clientIP, token string) bool {
ip := net.ParseIP(clientIP)
if ip == nil || !ip.IsLoopback() {
return false
}
switch reqPath {
case "/api/v2/core/xpack/sync/ssl":
return token != ""
case "/api/v2/core/settings/ssl/reload":
return true
default:
return false
}
}
+4
View File
@@ -23,6 +23,10 @@ func PasswordExpired() gin.HandlerFunc {
c.Next()
return
}
if c.GetBool("LOCAL_REQUEST") {
c.Next()
return
}
if strings.HasPrefix(c.Request.URL.Path, "/api/v2/core/auth") ||
c.Request.URL.Path == "/api/v2/core/settings/search" ||
c.Request.URL.Path == "/api/v2/core/settings/search/base" ||
+1 -1
View File
@@ -15,7 +15,7 @@ import (
func SessionAuth() gin.HandlerFunc {
return func(c *gin.Context) {
apiReq := c.GetBool("API_AUTH")
if isAnonymousAuthPath(c.Request.URL.Path) || apiReq {
if isAnonymousAuthPath(c.Request.URL.Path) || apiReq || c.GetBool("LOCAL_REQUEST") {
c.Next()
return
}