Skip to content

Commit

Permalink
appsec: fix IsSecurityError (#2746)
Browse files Browse the repository at this point in the history
Signed-off-by: Eliott Bouhana <eliott.bouhana@datadoghq.com>
  • Loading branch information
eliottness committed Jun 19, 2024
1 parent 2059670 commit c7dfa2a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 2 additions & 3 deletions appsec/events/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import "errors"

var _ error = (*BlockingSecurityEvent)(nil)

var securityError = &BlockingSecurityEvent{}

// BlockingSecurityEvent is the error type returned by function calls blocked by appsec.
// Even though appsec takes care of responding automatically to the blocked requests, it
// is your duty to abort the request handlers that are calling functions blocked by appsec.
Expand All @@ -29,5 +27,6 @@ func (*BlockingSecurityEvent) Error() string {

// IsSecurityError returns true if the error is a security event.
func IsSecurityError(err error) bool {
return errors.Is(err, securityError)
var secErr *BlockingSecurityEvent
return errors.As(err, &secErr)
}
3 changes: 2 additions & 1 deletion contrib/net/http/roundtripper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ func TestAppsec(t *testing.T) {
resp, err := client.RoundTrip(req.WithContext(r.Context()))

if enabled {
require.ErrorIs(t, err, &events.BlockingSecurityEvent{})
require.True(t, events.IsSecurityError(err))
} else {
require.NoError(t, err)
}
Expand Down Expand Up @@ -690,6 +690,7 @@ func TestAppsec(t *testing.T) {
require.Contains(t, appsecJSON, httpsec.ServerIoNetURLAddr)

require.Contains(t, serviceSpan.Tags(), "_dd.stack")
require.NotContains(t, serviceSpan.Tags(), "error.message")

// This is a nested event so it should contain the child span id in the service entry span
// TODO(eliott.bouhana): uncomment this once we have the child span id in the service entry span
Expand Down

0 comments on commit c7dfa2a

Please sign in to comment.