diff --git a/builtin/audit/file/backend.go b/builtin/audit/file/backend.go index d99010daba..9c95dd3ea8 100644 --- a/builtin/audit/file/backend.go +++ b/builtin/audit/file/backend.go @@ -53,6 +53,16 @@ func (b *Backend) LogRequest(auth *logical.Auth, req *logical.Request, outerErr return err } if !b.LogRaw { + // Before we copy the structure we must nil out some data + // otherwise we will cause reflection to panic and die + if req.Connection != nil && req.Connection.ConnState != nil { + origState := req.Connection.ConnState + req.Connection.ConnState = nil + defer func() { + req.Connection.ConnState = origState + }() + } + // Copy the structures cp, err := copystructure.Copy(auth) if err != nil { @@ -88,6 +98,16 @@ func (b *Backend) LogResponse( return err } if !b.LogRaw { + // Before we copy the structure we must nil out some data + // otherwise we will cause reflection to panic and die + if req.Connection != nil && req.Connection.ConnState != nil { + origState := req.Connection.ConnState + req.Connection.ConnState = nil + defer func() { + req.Connection.ConnState = origState + }() + } + // Copy the structure cp, err := copystructure.Copy(auth) if err != nil { diff --git a/builtin/audit/syslog/backend.go b/builtin/audit/syslog/backend.go index 79f6eb740f..cf3c6ceaa0 100644 --- a/builtin/audit/syslog/backend.go +++ b/builtin/audit/syslog/backend.go @@ -54,6 +54,16 @@ type Backend struct { func (b *Backend) LogRequest(auth *logical.Auth, req *logical.Request, outerErr error) error { if !b.logRaw { + // Before we copy the structure we must nil out some data + // otherwise we will cause reflection to panic and die + if req.Connection != nil && req.Connection.ConnState != nil { + origState := req.Connection.ConnState + req.Connection.ConnState = nil + defer func() { + req.Connection.ConnState = origState + }() + } + // Copy the structures cp, err := copystructure.Copy(auth) if err != nil { @@ -91,6 +101,16 @@ func (b *Backend) LogRequest(auth *logical.Auth, req *logical.Request, outerErr func (b *Backend) LogResponse(auth *logical.Auth, req *logical.Request, resp *logical.Response, err error) error { if !b.logRaw { + // Before we copy the structure we must nil out some data + // otherwise we will cause reflection to panic and die + if req.Connection != nil && req.Connection.ConnState != nil { + origState := req.Connection.ConnState + req.Connection.ConnState = nil + defer func() { + req.Connection.ConnState = origState + }() + } + // Copy the structure cp, err := copystructure.Copy(auth) if err != nil {