Skip to content

Commit

Permalink
use set for sensitiveHeaders (#802)
Browse files Browse the repository at this point in the history
Co-authored-by: Michi Hoffmann <cleptric@users.noreply.github.com>
  • Loading branch information
ribice and cleptric committed Apr 2, 2024
1 parent c10f51e commit 271dc49
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@ const (
LevelFatal Level = "fatal"
)

func getSensitiveHeaders() map[string]bool {
return map[string]bool{
"Authorization": true,
"Cookie": true,
"X-Forwarded-For": true,
"X-Real-Ip": true,
}
}

// SdkInfo contains all metadata about about the SDK being used.
type SdkInfo struct {
Name string `json:"name,omitempty"`
Expand Down Expand Up @@ -171,6 +162,13 @@ type Request struct {
Env map[string]string `json:"env,omitempty"`
}

var sensitiveHeaders = map[string]struct{}{
"Authorization": {},
"Cookie": {},
"X-Forwarded-For": {},
"X-Real-Ip": {},
}

// NewRequest returns a new Sentry Request from the given http.Request.
//
// NewRequest avoids operations that depend on network access. In particular, it
Expand Down Expand Up @@ -201,7 +199,6 @@ func NewRequest(r *http.Request) *Request {
env = map[string]string{"REMOTE_ADDR": addr, "REMOTE_PORT": port}
}
} else {
sensitiveHeaders := getSensitiveHeaders()
for k, v := range r.Header {
if _, ok := sensitiveHeaders[k]; !ok {
headers[k] = strings.Join(v, ",")
Expand Down

0 comments on commit 271dc49

Please sign in to comment.