Skip to content

Commit

Permalink
order imports
Browse files Browse the repository at this point in the history
Signed-off-by: Eliott Bouhana <[email protected]>
  • Loading branch information
eliottness committed Jun 3, 2024
1 parent af120e7 commit 2def74f
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 12 deletions.
9 changes: 9 additions & 0 deletions appsec/events/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
// It allows finer-grained integrations of appsec into your Go errors' management logic.
package events

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 @@ -22,3 +26,8 @@ type BlockingSecurityEvent struct{}
func (*BlockingSecurityEvent) Error() string {
return "request blocked by WAF"
}

// IsSecurityError returns true if the error is a security event.
func IsSecurityError(err error) bool {
return errors.Is(err, securityError)
}
1 change: 1 addition & 0 deletions contrib/google.golang.org/grpc/appsec.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package grpc

import (
"context"

"gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
"gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/dyngo"
"gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/emitter/grpcsec"
Expand Down
5 changes: 3 additions & 2 deletions contrib/labstack/echo.v4/appsec.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
package echo

import (
"gopkg.in/DataDog/dd-trace-go.v1/appsec/events"
"net/http"

"github.com/labstack/echo/v4"
"gopkg.in/DataDog/dd-trace-go.v1/appsec/events"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
"gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/emitter/httpsec"

"github.com/labstack/echo/v4"
)

func withAppSec(next echo.HandlerFunc, span tracer.Span) echo.HandlerFunc {
Expand Down
7 changes: 2 additions & 5 deletions contrib/net/http/roundtripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
package http

import (
"errors"
"fmt"
"gopkg.in/DataDog/dd-trace-go.v1/appsec/events"
"math"
"net/http"
"os"
"strconv"

"gopkg.in/DataDog/dd-trace-go.v1/appsec/events"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
Expand All @@ -26,8 +25,6 @@ type roundTripper struct {
cfg *roundTripperConfig
}

var securityError = &events.BlockingSecurityEvent{}

func (rt *roundTripper) RoundTrip(req *http.Request) (res *http.Response, err error) {
if rt.cfg.ignoreRequest(req) {
return rt.base.RoundTrip(req)
Expand Down Expand Up @@ -63,7 +60,7 @@ func (rt *roundTripper) RoundTrip(req *http.Request) (res *http.Response, err er
if rt.cfg.after != nil {
rt.cfg.after(res, span)
}
if !errors.Is(err, securityError) && (rt.cfg.errCheck == nil || rt.cfg.errCheck(err)) {
if !events.IsSecurityError(err) && (rt.cfg.errCheck == nil || rt.cfg.errCheck(err)) {
span.Finish(tracer.WithError(err))
} else {
span.Finish()
Expand Down
2 changes: 1 addition & 1 deletion internal/appsec/emitter/httpsec/roundtripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func ProtectRoundTrip(ctx context.Context, url string) error {
}

var err *events.BlockingSecurityEvent
// TODO: move the data listener as a setup function of httpsec.StartRoundTripperOperation(ars, <setup>)
// TODO: move the data listener as a setup function of httpsec.StartRoundTripperOperation(ars, <setup>)
dyngo.OnData(op, func(e *events.BlockingSecurityEvent) {
err = e
})
Expand Down
8 changes: 5 additions & 3 deletions internal/appsec/listener/sharedsec/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ package sharedsec
import (
"encoding/json"
"errors"
"github.com/DataDog/appsec-internal-go/limiter"
waf "github.com/DataDog/go-libddwaf/v3"
wafErrors "github.com/DataDog/go-libddwaf/v3/errors"

"gopkg.in/DataDog/dd-trace-go.v1/appsec/events"
"gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/dyngo"
"gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/emitter/sharedsec"
"gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/trace"
"gopkg.in/DataDog/dd-trace-go.v1/internal/log"

"github.com/DataDog/appsec-internal-go/limiter"
waf "github.com/DataDog/go-libddwaf/v3"
wafErrors "github.com/DataDog/go-libddwaf/v3/errors"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion internal/stacktrace/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
package stacktrace

import (
"github.com/tinylib/msgp/msgp"
"testing"

"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/mocktracer"
ddtracer "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
"gopkg.in/DataDog/dd-trace-go.v1/internal"

"github.com/stretchr/testify/require"
"github.com/tinylib/msgp/msgp"
)

func TestNewEvent(t *testing.T) {
Expand Down

0 comments on commit 2def74f

Please sign in to comment.