REALITY config: Return error when short id is too long (#5276)

Closes https://github.com/XTLS/Xray-core/issues/5273

---------

Co-authored-by: 风扇滑翔翼 <Fangliding.fshxy@outlook.com>
pull/5315/head
RPRX 2025-11-19 03:25:32 +00:00 committed by GitHub
parent 412bc17c12
commit 1a32d18c16
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 0 deletions

View File

@ -628,6 +628,9 @@ func (c *REALITYConfig) Build() (proto.Message, error) {
}
config.ShortIds = make([][]byte, len(c.ShortIds))
for i, s := range c.ShortIds {
if len(s) > 16 {
return nil, errors.New(`too long "shortIds[`, i, `]": `, s)
}
config.ShortIds[i] = make([]byte, 8)
if _, err = hex.Decode(config.ShortIds[i], []byte(s)); err != nil {
return nil, errors.New(`invalid "shortIds[`, i, `]": `, s)
@ -679,6 +682,9 @@ func (c *REALITYConfig) Build() (proto.Message, error) {
if len(c.ShortIds) != 0 {
return nil, errors.New(`non-empty "shortIds", please use "shortId" instead`)
}
if len(c.ShortIds) > 16 {
return nil, errors.New(`too long "shortId": `, c.ShortId)
}
config.ShortId = make([]byte, 8)
if _, err = hex.Decode(config.ShortId, []byte(c.ShortId)); err != nil {
return nil, errors.New(`invalid "shortId": `, c.ShortId)