-
Notifications
You must be signed in to change notification settings - Fork 10
/
http.go
61 lines (57 loc) · 1.64 KB
/
http.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
package obfuscate
import (
"net/url"
"strings"
"github.com/n9e/n9e-agentd/staging/datadog-agent/pkg/trace/pb"
)
// obfuscateHTTP obfuscates query strings and path segments containing digits in the span's
// "http.url" tag, when one or both of these options are enabled.
func (o *Obfuscator) obfuscateHTTP(span *pb.Span) {
if span.Meta == nil {
return
}
if !o.opts.HTTP.RemoveQueryString && !o.opts.HTTP.RemovePathDigits {
// nothing to do
return
}
const k = "http.url"
val, ok := span.Meta[k]
if !ok {
return
}
u, err := url.Parse(val)
if err != nil {
// should not happen for valid URLs, but better obfuscate everything
// rather than expose sensitive information when this option is on.
span.Meta[k] = "?"
return
}
if o.opts.HTTP.RemoveQueryString && u.RawQuery != "" {
u.ForceQuery = true // add the '?'
u.RawQuery = ""
}
if o.opts.HTTP.RemovePathDigits {
segs := strings.Split(u.Path, "/")
var changed bool
for i, seg := range segs {
for _, ch := range []byte(seg) {
if ch >= '0' && ch <= '9' {
// we can not set the question mark directly here because the url
// package will escape it into %3F, so we use this placeholder and
// replace it further down.
segs[i] = "/REDACTED/"
changed = true
break
}
}
}
if changed {
u.Path = strings.Join(segs, "/")
}
}
span.Meta[k] = strings.Replace(u.String(), "/REDACTED/", "?", -1)
}