@@ -25,6 +25,7 @@ const (
25
25
ja4hFullHashLength = 51
26
26
ja4hSubHashLength = 12
27
27
defaultLang = "0000"
28
+ emptyCookiesHash = "000000000000"
28
29
)
29
30
30
31
// httpMethod extracts the first two lowercase characters of the HTTP method.
@@ -77,6 +78,7 @@ func primaryLanguage(headers http.Header) string {
77
78
//cf. https://github.com/FoxIO-LLC/ja4/blob/main/python/ja4h.py#L13
78
79
lang = strings .ReplaceAll (lang , "-" , "" )
79
80
lang = strings .ReplaceAll (lang , ";" , "," )
81
+ lang = lang [:min (len (lang ), 4 )]
80
82
81
83
return strings .Split (lang , "," )[0 ] + strings .Repeat ("0" , 4 - len (lang ))
82
84
}
@@ -123,7 +125,7 @@ func hashTruncated(input string) string {
123
125
// jA4H_c computes a truncated SHA256 hash of sorted cookie names.
124
126
func jA4H_c (cookies []* http.Cookie ) string {
125
127
if len (cookies ) == 0 {
126
- return strings . Repeat ( "0" , truncatedHashLength )
128
+ return emptyCookiesHash
127
129
}
128
130
var builder strings.Builder
129
131
for i , cookie := range cookies {
@@ -138,7 +140,7 @@ func jA4H_c(cookies []*http.Cookie) string {
138
140
// jA4H_d computes a truncated SHA256 hash of cookie name-value pairs.
139
141
func jA4H_d (cookies []* http.Cookie ) string {
140
142
if len (cookies ) == 0 {
141
- return strings . Repeat ( "0" , truncatedHashLength )
143
+ return emptyCookiesHash
142
144
}
143
145
var builder strings.Builder
144
146
for i , cookie := range cookies {
0 commit comments