Skip to content

Commit 35eacaa

Browse files
committed
fix invalid hash with malformated accept-language header
1 parent 5c2c9d7 commit 35eacaa

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

pkg/appsec/ja4h/ja4h.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ func primaryLanguage(headers http.Header) string {
8080
lang = strings.ReplaceAll(lang, ";", ",")
8181
lang = lang[:min(len(lang), 4)]
8282

83-
return strings.Split(lang, ",")[0] + strings.Repeat("0", 4-len(lang))
83+
value := strings.Split(lang, ",")[0]
84+
return value + strings.Repeat("0", 4-len(value))
8485
}
8586

8687
// jA4H_a generates a summary fingerprint for the HTTP request.

pkg/appsec/ja4h/ja4h_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ func TestJA4H_A(t *testing.T) {
4949
},
5050
expectedResult: "ge11nn01aksj",
5151
},
52+
{
53+
name: "bad accept-language header 2",
54+
request: func() *http.Request {
55+
req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
56+
req.Header.Set("Accept-Language", ",")
57+
return req
58+
},
59+
expectedResult: "ge11nn010000",
60+
},
5261
}
5362

5463
for _, tt := range tests {

0 commit comments

Comments
 (0)