Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

appsec: fix IsSecurityError #2746

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading