mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 04:30:05 +00:00
为cloudflareCookies增加基本的合法性验证
This commit is contained in:
@@ -5,6 +5,8 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -275,7 +277,22 @@ func (cp *commonPage) terminal(c *gin.Context) {
|
||||
}, true)
|
||||
return
|
||||
}
|
||||
cloudflareCookies, _ := c.Cookie("CF_Authorization")
|
||||
cloudflareCookies, _ := c.Cookie("CF_Authorization")
|
||||
// CloudflareCookies合法性验证
|
||||
// 其应该包含.分隔的三组BASE64-URL编码
|
||||
if cloudflareCookies != "" {
|
||||
encodedCookies := strings.Split(cloudflareCookies, ".")
|
||||
if len(encodedCookies) == 3 {
|
||||
for i := 0; i < 3; i++ {
|
||||
if valid, _ := regexp.MatchString("^[A-Za-z0-9-_]+$", encodedCookies[i]); !valid {
|
||||
cloudflareCookies = ""
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cloudflareCookies = ""
|
||||
}
|
||||
}
|
||||
terminalData, _ := utils.Json.Marshal(&model.TerminalTask{
|
||||
Host: terminal.host,
|
||||
UseSSL: terminal.useSSL,
|
||||
|
||||
Reference in New Issue
Block a user