Skip to content

Commit

Permalink
Merge branch 'v1' into mackjmr/echo-no-debug-stack
Browse files Browse the repository at this point in the history
  • Loading branch information
knusbaum committed Jan 14, 2022
2 parents b9ba774 + 73af74d commit cb528da
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion contrib/labstack/echo.v4/echotrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func withAppSec(next echo.HandlerFunc) echo.HandlerFunc {
if err != nil {
remoteIP = req.RemoteAddr
}
httpsec.SetSecurityEventTags(span, events, remoteIP, args.Headers)
httpsec.SetSecurityEventTags(span, events, remoteIP, args.Headers, c.Response().Writer.Header())
}
}()
return next(c)
Expand Down
2 changes: 1 addition & 1 deletion internal/appsec/dyngo/instrumentation/httpsec/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func WrapHandler(handler http.Handler, span ddtrace.Span) http.Handler {
if err != nil {
remoteIP = r.RemoteAddr
}
SetSecurityEventTags(span, events, remoteIP, args.Headers)
SetSecurityEventTags(span, events, remoteIP, args.Headers, w.Header())
}()
handler.ServeHTTP(w, r)
})
Expand Down
6 changes: 5 additions & 1 deletion internal/appsec/dyngo/instrumentation/httpsec/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ func setEventSpanTags(span ddtrace.Span, events json.RawMessage) {
}

// SetSecurityEventTags sets the AppSec-specific span tags when a security event occurred into the service entry span.
func SetSecurityEventTags(span ddtrace.Span, events json.RawMessage, remoteIP string, headers map[string][]string) {
func SetSecurityEventTags(span ddtrace.Span, events json.RawMessage, remoteIP string, headers, respHeaders map[string][]string) {
setEventSpanTags(span, events)
span.SetTag("network.client.ip", remoteIP)
for h, v := range normalizeHTTPHeaders(headers) {
span.SetTag("http.request.headers."+h, v)
}
for h, v := range normalizeHTTPHeaders(respHeaders) {
span.SetTag("http.response.headers."+h, v)
}
}

// List of HTTP headers we collect and send.
Expand Down Expand Up @@ -87,6 +90,7 @@ func normalizeHTTPHeaders(headers map[string][]string) (normalized map[string]st
}
normalized = make(map[string]string)
for k, v := range headers {
k = strings.ToLower(k)
if i := sort.SearchStrings(collectedHTTPHeaders[:], k); i < len(collectedHTTPHeaders) && collectedHTTPHeaders[i] == k {
normalized[k] = strings.Join(v, ",")
}
Expand Down

0 comments on commit cb528da

Please sign in to comment.