Skip to content

Commit 142f07a

Browse files
committed
Check if request api key is in the range
1 parent 48b1ab3 commit 142f07a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

proxy/processor.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ const (
2222
apiKeyUnset = int16(-1) // not in protocol
2323
apiKeySaslAuth = int16(-2) // not in protocol
2424
apiKeySaslHandshake = int16(17)
25+
26+
minRequestApiKey = int16(0) // 0 - Produce
27+
maxRequestApiKey = int16(100) // so far 42 is the last (reserve some for the feature)
2528
)
2629

2730
type ProcessorConfig struct {
@@ -138,6 +141,10 @@ nextRequest:
138141
}
139142
//logrus.Printf("Kafka request length %v, key %v, version %v", requestKeyVersion.Length, requestKeyVersion.ApiKey, requestKeyVersion.ApiVersion)
140143

144+
if requestKeyVersion.ApiKey < minRequestApiKey || requestKeyVersion.ApiKey > maxRequestApiKey {
145+
return true, fmt.Errorf("api key %d is invalid", requestKeyVersion.ApiKey)
146+
}
147+
141148
proxyRequestsTotal.WithLabelValues(brokerAddress, strconv.Itoa(int(requestKeyVersion.ApiKey)), strconv.Itoa(int(requestKeyVersion.ApiVersion))).Inc()
142149
proxyRequestsBytes.WithLabelValues(brokerAddress).Add(float64(requestKeyVersion.Length + 4))
143150

0 commit comments

Comments
 (0)