Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMHSanaei <ho3ein.sanaei@gmail.com>2023-05-15 15:29:27 +0300
committerMHSanaei <ho3ein.sanaei@gmail.com>2023-05-15 15:29:27 +0300
commit1dc5452f1ded39f3bf1131a0eb6a3fef0d3da7a3 (patch)
treee262273960f27b5541ce43702987d0f478448ab2 /web/controller/server.go
parenta0daf2fae2365aceec59ea362dfa35c0983f0191 (diff)
security issue - CVE-2023-29401
Gin Web Framework does not properly sanitize filename parameter of Context.FileAttachment function References gin-gonic/gin#3555 gin-gonic/gin#3556 https://pkg.go.dev/vuln/GO-2023-1737
Diffstat (limited to 'web/controller/server.go')
-rw-r--r--web/controller/server.go20
1 files changed, 19 insertions, 1 deletions
diff --git a/web/controller/server.go b/web/controller/server.go
index 9e649e6c..2db6e7fd 100644
--- a/web/controller/server.go
+++ b/web/controller/server.go
@@ -1,6 +1,9 @@
package controller
import (
+ "fmt"
+ "net/http"
+ "regexp"
"time"
"x-ui/web/global"
"x-ui/web/service"
@@ -8,6 +11,8 @@ import (
"github.com/gin-gonic/gin"
)
+var filenameRegex = regexp.MustCompile(`^[a-zA-Z0-9_\-.]+$`)
+
type ServerController struct {
BaseController
@@ -136,14 +141,27 @@ func (a *ServerController) getDb(c *gin.Context) {
jsonMsg(c, "get Database", err)
return
}
+
+ filename := "x-ui.db"
+
+ if !isValidFilename(filename) {
+ c.AbortWithError(http.StatusBadRequest, fmt.Errorf("invalid filename"))
+ return
+ }
+
// Set the headers for the response
c.Header("Content-Type", "application/octet-stream")
- c.Header("Content-Disposition", "attachment; filename=x-ui.db")
+ c.Header("Content-Disposition", "attachment; filename="+filename)
// Write the file contents to the response
c.Writer.Write(db)
}
+func isValidFilename(filename string) bool {
+ // Validate that the filename only contains allowed characters
+ return filenameRegex.MatchString(filename)
+}
+
func (a *ServerController) importDB(c *gin.Context) {
// Get the file from the request body
file, _, err := c.Request.FormFile("db")