Skip to content

Commit 2fc470c

Browse files
committed
feat(pb/relayd): add fingerprints object
Release-Status: cut Signed-off-by: Xe Iaso <[email protected]>
1 parent e810bdb commit 2fc470c

File tree

4 files changed

+61
-32
lines changed

4 files changed

+61
-32
lines changed

cmd/relayd/main.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ func main() {
169169
t0 := time.Now()
170170

171171
var foundJa3N, foundJa4 string
172+
foundJa4H := ja4h.JA4H(r)
173+
fingerprints := map[string]string{
174+
"ja4h": foundJa4H,
175+
}
172176

173177
host, _, _ := net.SplitHostPort(r.RemoteAddr)
174178
if host != "" {
@@ -187,27 +191,31 @@ func main() {
187191

188192
if tcpFP := GetTCPFingerprint(r); tcpFP != nil {
189193
r.Header.Set("X-JA4T-Fingerprint", tcpFP.String())
194+
fingerprints["ja4t"] = tcpFP.String()
190195
}
191196

192197
reqID := uuid.Must(uuid.NewV7()).String()
193-
rl := relayd.RequestLogFromRequest(r, host, reqID, foundJa4)
194198

195199
r.Header.Set("X-Forwarded-Host", r.Host)
196200
r.Header.Set("X-Forwarded-Proto", "https")
197201
r.Header.Set("X-Forwarded-Scheme", "https")
198202
r.Header.Set("X-Request-Id", reqID)
199203
r.Header.Set("X-Scheme", "https")
200204
r.Header.Set("X-HTTP-Protocol", r.Proto)
201-
r.Header.Set("X-JA4H-Fingerprint", ja4h.JA4H(r))
205+
r.Header.Set("X-JA4H-Fingerprint", foundJa4H)
202206

203207
if foundJa3N != "" {
204208
r.Header.Set("X-JA3N-Fingerprint", foundJa3N)
209+
fingerprints["ja3n"] = foundJa3N
205210
}
206211

207212
if foundJa4 != "" {
208213
r.Header.Set("X-JA4-Fingerprint", foundJa4)
214+
fingerprints["ja4"] = foundJa4
209215
}
210216

217+
rl := relayd.RequestLogFromRequest(r, host, reqID, fingerprints)
218+
211219
headers, _ := json.Marshal(r.Header)
212220

213221
if ja4 := foundJa4; db != nil && ja4 != "" {

gen/within/website/x/relayd/v1/relayd.pb.go

Lines changed: 35 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/within/website/x/relayd/v1/requestlog.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ import (
77
"google.golang.org/protobuf/types/known/timestamppb"
88
)
99

10-
func RequestLogFromRequest(r *http.Request, ipAddress, requestID, ja4 string) *RequestLog {
10+
func RequestLogFromRequest(r *http.Request, ipAddress, requestID string, fingerprints map[string]string) *RequestLog {
1111
result := &RequestLog{
12-
RequestDate: timestamppb.Now(),
13-
Host: r.Host,
14-
Method: r.Method,
15-
Path: r.URL.Path,
16-
Query: map[string]string{},
17-
Headers: map[string]string{},
18-
RemoteIp: ipAddress,
19-
Ja4: ja4,
20-
RequestId: requestID,
12+
RequestDate: timestamppb.Now(),
13+
Host: r.Host,
14+
Method: r.Method,
15+
Path: r.URL.Path,
16+
Query: map[string]string{},
17+
Headers: map[string]string{},
18+
RemoteIp: ipAddress,
19+
Ja3N: fingerprints["ja3n"],
20+
Ja4: fingerprints["ja4"],
21+
RequestId: requestID,
22+
Fingerprints: fingerprints,
2123
}
2224

2325
for k, v := range r.URL.Query() {
@@ -28,6 +30,8 @@ func RequestLogFromRequest(r *http.Request, ipAddress, requestID, ja4 string) *R
2830
switch {
2931
case k == "Cookie", k == "Authorization":
3032
continue
33+
case strings.HasPrefix(k, "X-"):
34+
continue
3135
}
3236
result.Headers[k] = strings.Join(v, ",")
3337
}

pb/within/website/x/relayd/v1/relayd.proto

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ message RequestLog {
1414
map<string, string> headers = 7;
1515
string remote_ip = 8;
1616
string ja3n = 9 [ deprecated = true ];
17-
string ja4 = 10;
17+
string ja4 = 10 [ deprecated = true ];
1818
string request_id = 11;
1919
int32 status_code = 12;
20+
map<string, string> fingerprints = 13;
2021
}

0 commit comments

Comments
 (0)