Skip to content

Commit c61f014

Browse files
committed
more data validation
1 parent 58f3217 commit c61f014

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

contrib/haproxy/stream-processing-offload/haproxy_mp.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,24 @@ func (a *requestHeadersHAProxy) NewRequest(ctx context.Context) (*http.Request,
2929
return nil, err
3030
}
3131

32+
authority := headers.Get("Host")
3233
method := getStringValue(a.msg, "method")
3334
path := getStringValue(a.msg, "path")
3435
https := getBoolValue(a.msg, "https")
3536
remoteIp := getIPValue(a.msg, "ip")
3637
remotePort := strconv.Itoa(getIntValue(a.msg, "ip_port"))
3738

39+
if authority == "" || method == "" || path == "" || remoteIp == nil {
40+
return nil, fmt.Errorf("missing required values in the http request SPOE message")
41+
}
42+
3843
var tlsState *tls.ConnectionState
3944
scheme := "http"
4045
if https {
4146
tlsState = &tls.ConnectionState{}
4247
scheme = "https"
4348
}
4449

45-
authority := headers.Get("Host")
46-
if authority == "" {
47-
return nil, fmt.Errorf("no Host header")
48-
}
49-
5050
// Define if a body is present based on Content-Length header
5151
contentLength := headers.Get("Content-Length")
5252
if contentLength != "" {

contrib/haproxy/stream-processing-offload/haproxy_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"context"
1010
"encoding/json"
1111
"fmt"
12+
"net"
1213
"os"
1314
"regexp"
1415
"strconv"
@@ -567,6 +568,14 @@ func sendProcessingRequestHeaders(t *testing.T, handler func(*request.Request),
567568
mKv.Add("https", true)
568569
mKv.Add("timeout", "1s")
569570

571+
if ip, ok := headers["X-Forwarded-For"]; ok {
572+
mKv.Add("ip", net.ParseIP(ip))
573+
} else {
574+
mKv.Add("ip", net.ParseIP("123.123.123.123"))
575+
}
576+
577+
mKv.Add("ip_port", 12345)
578+
570579
messages := message.Messages{
571580
&message.Message{Name: "http-request-headers-msg", KV: mKv},
572581
}
@@ -608,7 +617,6 @@ func sendProcessingRequestBody(t *testing.T, handler func(*request.Request), bod
608617
t.Helper()
609618

610619
mKv := kv.NewKV()
611-
mKv.Add("body_size", len(body))
612620
mKv.Add("body", body)
613621
mKv.Add("span_id", spanId)
614622

contrib/haproxy/stream-processing-offload/hdrsbin_parser.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ func readUvarintAt(buf []byte, p int) (val uint64, next int, err error) {
2525
// The list is terminated by a pair of empty strings (length 0 for both name and value).
2626
// https://www.haproxy.com/documentation/haproxy-configuration-manual/latest/#7.3.6-req.hdrs_bin
2727
func parseHAProxyReqHdrsBin(buf []byte) (http.Header, error) {
28+
if buf == nil || len(buf) == 0 {
29+
return nil, fmt.Errorf("empty headers buffer")
30+
}
31+
2832
headers := make(http.Header)
2933

3034
p := 0

contrib/haproxy/stream-processing-offload/hdrsbin_parser_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ func TestParseHAProxyReqHdrsBin_Table(t *testing.T) {
150150
},
151151
want: http.Header{"A": {"B"}},
152152
},
153+
{
154+
name: "Malformed_Empty",
155+
build: func() []byte { return nil },
156+
wantErr: true,
157+
},
153158
}
154159

155160
for _, tc := range tests {

0 commit comments

Comments
 (0)