mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-08-23 10:06:48 +08:00
Fix DoS attack vulnerability in CommandSwitchAccountFactory
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
@@ -35,3 +36,23 @@ func TestSwitchAccount(t *testing.T) {
|
||||
t.Error(r)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSwitchAccountBugOffByOne(t *testing.T) {
|
||||
sa := &protocol.CommandSwitchAccount{
|
||||
Port: 1234,
|
||||
ID: uuid.New(),
|
||||
AlterIds: 1024,
|
||||
Level: 128,
|
||||
ValidMin: 16,
|
||||
}
|
||||
|
||||
buffer := buf.New()
|
||||
csaf := CommandSwitchAccountFactory{}
|
||||
common.Must(csaf.Marshal(sa, buffer))
|
||||
|
||||
Payload := buffer.Bytes()
|
||||
|
||||
cmd, err := csaf.Unmarshal(Payload[:len(Payload)-1])
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, cmd)
|
||||
}
|
||||
|
Reference in New Issue
Block a user