@@ -2,6 +2,7 @@ package ray2sing
22
33import (
44 "net/url"
5+ "regexp"
56 "strings"
67
78 T "github.com/sagernet/sing-box/option"
@@ -46,14 +47,17 @@ func ParseUrl(inputURL string, defaultPort uint16) (*UrlSchema, error) {
4647 Name : parsedURL .Fragment ,
4748 Params : make (map [string ]string ),
4849 }
49- userInfo , err := decodeBase64IfNeeded (data .Username )
50- // fmt.Print(userInfo)
51- if err == nil {
52- // If decoding is successful, use the decoded string
53- userDetails := strings .SplitN (userInfo , ":" , 2 )
54- if len (userDetails ) > 1 {
55- data .Username = userDetails [0 ]
56- data .Password = userDetails [1 ]
50+ if ! isBase64CharsOnly (data .Username ) {
51+ userInfo , err := decodeBase64IfNeeded (data .Username )
52+
53+ // fmt.Print(userInfo)
54+ if err == nil && isValidChar (userInfo ) {
55+ // If decoding is successful, use the decoded string
56+ userDetails := strings .Split (userInfo , ":" )
57+ if len (userDetails ) == 2 {
58+ data .Username = userDetails [0 ]
59+ data .Password = userDetails [1 ]
60+ }
5761 }
5862 }
5963
@@ -70,3 +74,15 @@ func getPassword(u *url.URL) string {
7074 }
7175 return ""
7276}
77+
78+ var base64CharRegex = regexp .MustCompile (`^[A-Za-z0-9+/=]+$` )
79+
80+ func isBase64CharsOnly (s string ) bool {
81+ return base64CharRegex .MatchString (s )
82+ }
83+
84+ var validCharRegex = regexp .MustCompile (`^[A-Za-z0-9+/=_)( !~@#$%^&*]+$` )
85+
86+ func isValidChar (s string ) bool {
87+ return validCharRegex .MatchString (s )
88+ }
0 commit comments