mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-09-21 18:50:13 +00:00
fix(rpc): enforce magic ff05ff05 on IOStream init
The inline magic check expressed the *invalid* form as \`byte0 != 0xff && byte1 != 0x05 && byte2 != 0xff && byte3 == 0x05\`, relying on && to detect a four-byte mismatch. Because && short-circuits, any payload whose byte0 happened to be 0xff was treated as a valid magic even if the remaining bytes did not match — almost every random payload slipped through and only the stream-UUID layer above stood between a caller with a valid agent secret and a live IOStream session. Extract the check into isValidIOStreamMagic stated positively (all four bytes must match) so short-circuit reasoning cannot reintroduce the bug. Co-authored-by: naiba/CloudCode <hi+cloudcode@nai.ba>
This commit is contained in:
@@ -216,8 +216,9 @@ func (s *NezhaHandler) IOStream(stream pb.NezhaService_IOStreamServer) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// ff05ff05 是 Nezha 的魔数,用于标识流 ID
|
||||
if id == nil || len(id.Data) < 4 || (id.Data[0] != 0xff && id.Data[1] != 0x05 && id.Data[2] != 0xff && id.Data[3] == 0x05) {
|
||||
// ff05ff05 是 Nezha 的魔数,用于标识流 ID。校验由 isValidIOStreamMagic 完成,
|
||||
// 历史 inline 检查曾因 && 短路放过几乎全部非魔数 payload (byte0==0xff 即通过)。
|
||||
if id == nil || !isValidIOStreamMagic(id.Data) {
|
||||
return fmt.Errorf("invalid stream id")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user