mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-05-14 10:00:34 +00:00
refactor: simplify browser dialer UUID path validation
Agent-Logs-Url: https://github.com/XTLS/Xray-core/sessions/9288cc3c-d788-49d9-8bdc-f03281c238bf Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
8fca7745fb
commit
9ad099774a
@@ -11,6 +11,7 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
pathlib "path"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -35,7 +36,8 @@ var dialerServers map[string]*dialerServer
|
||||
var mu sync.RWMutex
|
||||
|
||||
const browserDialerSubprotocol = "browser-dialer"
|
||||
const uuidPathLength = 37
|
||||
|
||||
var uuidPathPattern = regexp.MustCompile(`^/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$`)
|
||||
|
||||
var upgrader = &websocket.Upgrader{
|
||||
ReadBufferSize: 0,
|
||||
@@ -97,7 +99,7 @@ func parseBrowserDialerAddress(addr string) (*browserDialerAddress, bool) {
|
||||
if cleanPath == "." || cleanPath == "/" || cleanPath != path {
|
||||
return nil, false
|
||||
}
|
||||
if !isUUIDPath(cleanPath) {
|
||||
if !uuidPathPattern.MatchString(cleanPath) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
@@ -107,30 +109,6 @@ func parseBrowserDialerAddress(addr string) (*browserDialerAddress, bool) {
|
||||
}, true
|
||||
}
|
||||
|
||||
func isUUIDPath(path string) bool {
|
||||
if len(path) != uuidPathLength || path[0] != '/' || strings.Count(path, "/") != 1 {
|
||||
return false
|
||||
}
|
||||
|
||||
u := path[1:]
|
||||
for i := 0; i < len(u); i++ {
|
||||
c := u[i]
|
||||
switch i {
|
||||
case 8, 13, 18, 23:
|
||||
if c != '-' {
|
||||
return false
|
||||
}
|
||||
default:
|
||||
isHex := (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')
|
||||
if !isHex {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func newDialerInstance(path string) *dialerInstance {
|
||||
page := bytes.ReplaceAll(webpage, []byte("dialerPath"), []byte(strings.TrimPrefix(path, "/")))
|
||||
dialer := &dialerInstance{
|
||||
|
||||
Reference in New Issue
Block a user