mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-16 10:05:00 +03:00
fix(inbounds): refuse a Shadowsocks-2022 server key xray-core cannot parse
xray-core parses the inbound-level Shadowsocks-2022 key with ParseKey and refuses one of the wrong size while building the inbound, which keeps the whole core from starting, not only that inbound. Only client keys were checked, so an API caller posting a 32-byte key on aes-128 (or keeping a 16-byte key after switching to aes-256/chacha20) saved fine and took Xray down. AddInbound and UpdateInbound now reject such a key with a message that names the method and the size it needs. The check uses the core's own GetCipherMethod/ParseKey, so a raw non-base64 key the core accepts stays valid. Startup also replaces a stored wrong-size server key: that inbound never worked, so no client holds a working copy of it.
This commit is contained in:
@@ -509,6 +509,29 @@ func shadowsocksKeyBytes(method string) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// validateShadowsocks2022ServerKey refuses a server key xray-core cannot parse:
|
||||
// the core then fails to build the inbound and does not start at all.
|
||||
func validateShadowsocks2022ServerKey(protocol model.Protocol, settings string) error {
|
||||
if protocol != model.Shadowsocks {
|
||||
return nil
|
||||
}
|
||||
var parsed struct {
|
||||
Method string `json:"method"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
if json.Unmarshal([]byte(settings), &parsed) != nil {
|
||||
return nil
|
||||
}
|
||||
n := xray.Shadowsocks2022KeyBytes(parsed.Method)
|
||||
if n == 0 {
|
||||
return nil
|
||||
}
|
||||
if !xray.ValidShadowsocks2022Key(parsed.Method, parsed.Password) {
|
||||
return common.NewErrorf("shadowsocks inbound password: %s needs a %d-byte key, base64 encoded", parsed.Method, n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// normalizeShadowsocksClientKeys rewrites any Shadowsocks-2022 client password
|
||||
// whose decoded length no longer matches settings.method, which happens after the
|
||||
// inbound method is switched between ciphers of different key sizes (e.g.
|
||||
|
||||
Reference in New Issue
Block a user