Skip to content

Commit

Permalink
Option to not log raw request body
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjtwomey committed Mar 25, 2024
1 parent 18badb0 commit b3239b0
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions audit/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ type Options struct {
SkipQueryParams bool
SkipformParams bool
SkipRequestBody bool
// Option to not include raw request data with the log
SkipLogRawBody bool
}

// Audit entry.
Expand Down Expand Up @@ -214,8 +216,14 @@ func (a *Audit) filterFields(r *http.Request, opts Options) {
if bodyIsJSON && len(a.RequestBody) > 0 {
err := json.Unmarshal(a.RequestBody, &body)
if err != nil {
opts.Auditor.Log(r, errors.Wrapf(err, "could not parse body for %s %s: %s",
r.Method, r.URL.String(), stringutil.Left(string(a.RequestBody), 4000)))
msgFmt := "could not parse body for %s %s"
msgArgs := []interface{}{r.Method, r.URL.String()}

if !opts.SkipLogRawBody {
msgFmt += ": %s"
msgArgs = append(msgArgs, stringutil.Left(string(a.RequestBody), 4000))
}
opts.Auditor.Log(r, errors.Wrapf(err, msgFmt, msgArgs...))
}
}

Expand Down

0 comments on commit b3239b0

Please sign in to comment.