Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: When ClientOptions.SendDefaultPii is false, send http headers without sensitive data #524

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion fasthttp/sentryfasthttp_test.go
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
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
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 {
cleptric marked this conversation as resolved.
Show resolved Hide resolved
sensitiveHeaders := getSensitiveHeaders()
Expand Down
6 changes: 5 additions & 1 deletion interfaces_test.go
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