analyzer: make http3/quic handling more reliable
Some checks failed
Quality check / Tests (push) Has been cancelled
Quality check / Static analysis (push) Has been cancelled

This commit is contained in:
2026-02-11 15:53:26 +05:30
parent 43cb4755d0
commit a4baa1b1a3
2 changed files with 13 additions and 3 deletions

View File

@@ -47,9 +47,6 @@ func parseLongHeader(b *bytes.Reader) (*Header, error) {
return nil, err return nil, err
} }
h.Version = ver h.Version = ver
if h.Version != 0 && typeByte&0x40 == 0 {
return nil, errors.New("not a QUIC packet")
}
destConnIDLen, err := b.ReadByte() destConnIDLen, err := b.ReadByte()
if err != nil { if err != nil {
return nil, err return nil, err

View File

@@ -40,6 +40,7 @@ func (a *QUICAnalyzer) NewUDP(info analyzer.UDPInfo, logger analyzer.Logger) ana
type quicStream struct { type quicStream struct {
logger analyzer.Logger logger analyzer.Logger
invalidCount int invalidCount int
debugCount int
frames map[int64][]byte frames map[int64][]byte
maxEnd int64 maxEnd int64
} }
@@ -55,6 +56,10 @@ func (s *quicStream) Feed(rev bool, data []byte) (u *analyzer.PropUpdate, done b
if errors.Is(err, quic.ErrNotInitialPacket) { if errors.Is(err, quic.ErrNotInitialPacket) {
return nil, false return nil, false
} }
if s.debugCount < 4 {
s.logger.Debugf("failed to read QUIC CRYPTO frames: %v", err)
s.debugCount++
}
s.invalidCount++ s.invalidCount++
return nil, s.invalidCount >= quicInvalidCountThreshold return nil, s.invalidCount >= quicInvalidCountThreshold
} }
@@ -73,6 +78,10 @@ func (s *quicStream) Feed(rev bool, data []byte) (u *analyzer.PropUpdate, done b
if pl[0] != internal.TypeClientHello { if pl[0] != internal.TypeClientHello {
// Not a ClientHello (e.g. server-direction CRYPTO); ignore. // Not a ClientHello (e.g. server-direction CRYPTO); ignore.
if s.debugCount < 4 {
s.logger.Debugf("CRYPTO payload does not start with ClientHello: type=%d", pl[0])
s.debugCount++
}
return nil, false return nil, false
} }
@@ -88,6 +97,10 @@ func (s *quicStream) Feed(rev bool, data []byte) (u *analyzer.PropUpdate, done b
m := internal.ParseTLSClientHelloMsgData(&utils.ByteBuffer{Buf: pl[4 : 4+chLen]}) m := internal.ParseTLSClientHelloMsgData(&utils.ByteBuffer{Buf: pl[4 : 4+chLen]})
if m == nil { if m == nil {
if s.debugCount < 4 {
s.logger.Debugf("failed to parse TLS ClientHello from QUIC CRYPTO payload")
s.debugCount++
}
s.invalidCount++ s.invalidCount++
return nil, s.invalidCount >= quicInvalidCountThreshold return nil, s.invalidCount >= quicInvalidCountThreshold
} }