mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-12-01 14:18:36 +00:00
fix: Validate VLESS encryption padding
This commit is contained in:
@@ -248,7 +248,8 @@ func ParsePadding(padding string, paddingLens, paddingGaps *[][3]int) (err error
|
||||
if padding == "" {
|
||||
return
|
||||
}
|
||||
maxLen := 0
|
||||
const maximumPaddingLength = 18 + 65535
|
||||
remainingPaddingLength := maximumPaddingLength
|
||||
for i, s := range strings.Split(padding, ".") {
|
||||
x := strings.Split(s, "-")
|
||||
if len(x) < 3 || x[0] == "" || x[1] == "" || x[2] == "" {
|
||||
@@ -268,15 +269,16 @@ func ParsePadding(padding string, paddingLens, paddingGaps *[][3]int) (err error
|
||||
return E.New("first padding length must not be smaller than 35")
|
||||
}
|
||||
if i%2 == 0 {
|
||||
paddingLength := max(y[1], y[2])
|
||||
if paddingLength > remainingPaddingLength {
|
||||
return E.New("total padding length must not be larger than ", maximumPaddingLength)
|
||||
}
|
||||
remainingPaddingLength -= paddingLength
|
||||
*paddingLens = append(*paddingLens, y)
|
||||
maxLen += max(y[1], y[2])
|
||||
} else {
|
||||
*paddingGaps = append(*paddingGaps, y)
|
||||
}
|
||||
}
|
||||
if maxLen > 18+65535 {
|
||||
return E.New("total padding length must not be larger than 65553")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
stdtls "crypto/tls"
|
||||
"encoding/base64"
|
||||
"net"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
@@ -443,6 +444,8 @@ type clientEncryptionConfig struct {
|
||||
padding string
|
||||
}
|
||||
|
||||
var clientEncryptionPaddingPattern = regexp.MustCompile(`^[0-9]+-[0-9]+-[0-9]+$`)
|
||||
|
||||
func parseClientEncryption(raw string) (clientEncryptionConfig, error) {
|
||||
var cfg clientEncryptionConfig
|
||||
raw = strings.TrimSpace(raw)
|
||||
@@ -481,7 +484,7 @@ func parseClientEncryption(raw string) (clientEncryptionConfig, error) {
|
||||
if segment == "" {
|
||||
return cfg, E.New("invalid empty segment in encryption string")
|
||||
}
|
||||
if paddingPhase && len(segment) < 20 {
|
||||
if paddingPhase && len(segment) < 20 && clientEncryptionPaddingPattern.MatchString(segment) {
|
||||
paddingParts = append(paddingParts, segment)
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user