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:
MHSanaei
2026-10-11 20:42:23 +02:00
parent b124af2a1b
commit b9e1d3afee
6 changed files with 229 additions and 0 deletions
+34
View File
@@ -181,6 +181,9 @@ func initModels() error {
if err := migrateShadowsocksRemovedCiphers(); err != nil {
return err
}
if err := repairShadowsocks2022ServerKeys(); err != nil {
return err
}
if err := migrateVmessRemovedSecurities(); err != nil {
return err
}
@@ -987,6 +990,37 @@ func migrateShadowsocksRemovedCiphers() error {
return nil
}
// repairShadowsocks2022ServerKeys replaces a stored server key xray-core cannot
// parse; that inbound never worked, as the core refuses to start with it.
func repairShadowsocks2022ServerKeys() error {
var inbounds []model.Inbound
if err := db.Where("protocol = ?", model.Shadowsocks).Find(&inbounds).Error; err != nil {
return err
}
for _, inbound := range inbounds {
var settings map[string]any
if json.Unmarshal([]byte(inbound.Settings), &settings) != nil {
continue
}
method, _ := settings["method"].(string)
n := xray.Shadowsocks2022KeyBytes(method)
if key, _ := settings["password"].(string); n == 0 || xray.ValidShadowsocks2022Key(method, key) {
continue
}
settings["password"] = random.Base64Bytes(n)
newSettings, err := json.MarshalIndent(settings, "", " ")
if err != nil {
return err
}
if err := db.Model(&model.Inbound{}).Where("id = ?", inbound.Id).
Update("settings", string(newSettings)).Error; err != nil {
return err
}
log.Printf("Inbound %q: replaced a %s server key of the wrong size; its share links changed", inbound.Tag, method)
}
return nil
}
// migrateVmessRemovedSecurities rewrites the vmess "none"/"zero" security
// values that xray-core v26.7.11 removed to "auto" (what the core now treats
// them as), on both the clients column and each vmess inbound's settings.