Skip to content

Commit

Permalink
feat: When ClientOptions.SendDefaultPii is false, send http headers w…
Browse files Browse the repository at this point in the history
…ithout sensitive data (#524)

Co-authored-by: Michi Hoffmann <cleptric@users.noreply.github.com>
  • Loading branch information
ikorihn and cleptric authored Jan 12, 2023
1 parent 932dcf0 commit 231e816
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
1 change: 0 additions & 1 deletion fasthttp/sentryfasthttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ func TestIntegration(t *testing.T) {

eventsCh := make(chan *sentry.Event, len(tests))
err := sentry.Init(sentry.ClientOptions{
SendDefaultPII: true,
BeforeSend: func(event *sentry.Event, hint *sentry.EventHint) *sentry.Event {
eventsCh <- event
return event
Expand Down
1 change: 0 additions & 1 deletion http/sentryhttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ func TestIntegration(t *testing.T) {

eventsCh := make(chan *sentry.Event, len(tests))
err := sentry.Init(sentry.ClientOptions{
SendDefaultPII: true,
BeforeSend: func(event *sentry.Event, hint *sentry.EventHint) *sentry.Event {
eventsCh <- event
return event
Expand Down
26 changes: 12 additions & 14 deletions interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,21 +169,19 @@ func NewRequest(r *http.Request) *Request {
var env map[string]string
headers := map[string]string{}

if client := CurrentHub().Client(); client != nil {
if client.Options().SendDefaultPII {
// We read only the first Cookie header because of the specification:
// https://tools.ietf.org/html/rfc6265#section-5.4
// When the user agent generates an HTTP request, the user agent MUST NOT
// attach more than one Cookie header field.
cookies = r.Header.Get("Cookie")

for k, v := range r.Header {
headers[k] = strings.Join(v, ",")
}
if client := CurrentHub().Client(); client != nil && client.Options().SendDefaultPII {
// We read only the first Cookie header because of the specification:
// https://tools.ietf.org/html/rfc6265#section-5.4
// When the user agent generates an HTTP request, the user agent MUST NOT
// attach more than one Cookie header field.
cookies = r.Header.Get("Cookie")

if addr, port, err := net.SplitHostPort(r.RemoteAddr); err == nil {
env = map[string]string{"REMOTE_ADDR": addr, "REMOTE_PORT": port}
}
for k, v := range r.Header {
headers[k] = strings.Join(v, ",")
}

if addr, port, err := net.SplitHostPort(r.RemoteAddr); err == nil {
env = map[string]string{"REMOTE_ADDR": addr, "REMOTE_PORT": port}
}
} else {
sensitiveHeaders := getSensitiveHeaders()
Expand Down
6 changes: 5 additions & 1 deletion interfaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func TestNewRequest(t *testing.T) {
r.Header.Add("Cookie", "foo=bar")
r.Header.Add("X-Forwarded-For", "127.0.0.1")
r.Header.Add("X-Real-Ip", "127.0.0.1")
r.Header.Add("Some-Header", "some-header value")

got := NewRequest(r)
want := &Request{
Expand All @@ -94,6 +95,7 @@ func TestNewRequest(t *testing.T) {
"Host": "example.com",
"X-Forwarded-For": "127.0.0.1",
"X-Real-Ip": "127.0.0.1",
"Some-Header": "some-header value",
},
Env: map[string]string{
"REMOTE_ADDR": "192.0.2.1",
Expand All @@ -112,6 +114,7 @@ func TestNewRequestWithNoPII(t *testing.T) {
r.Header.Add("Cookie", "foo=bar")
r.Header.Add("X-Forwarded-For", "127.0.0.1")
r.Header.Add("X-Real-Ip", "127.0.0.1")
r.Header.Add("Some-Header", "some-header value")

got := NewRequest(r)
want := &Request{
Expand All @@ -121,7 +124,8 @@ func TestNewRequestWithNoPII(t *testing.T) {
QueryString: "q=sentry",
Cookies: "",
Headers: map[string]string{
"Host": "example.com",
"Host": "example.com",
"Some-Header": "some-header value",
},
Env: nil,
}
Expand Down

0 comments on commit 231e816

Please # to comment.