Skip to content

Commit 7912a70

Browse files
committed
misc suggestions from @Julio-Guerra
Signed-off-by: Eliott Bouhana <[email protected]>
1 parent e8e01e1 commit 7912a70

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

Diff for: appsec/events/block.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33
// This product includes software developed at Datadog (https://www.datadoghq.com/).
44
// Copyright 2022 Datadog, Inc.
55

6-
// Package events provides the types and interfaces for the appsec event system.
7-
// User-facing events can be returned by the appsec package to signal that a request was blocked.
8-
// Handling these events differently than other errors is crucial to not leak information to an attacker.
6+
// Package events provides security event types that appsec can return in function calls it monitors when blocking them.
7+
// It allows finer-grained integrations of appsec into your Go errors' management logic.
98
package events
109

1110
var _ error = (*BlockingSecurityEvent)(nil)
1211

13-
// BlockingSecurityEvent is an event that signals that a request was blocked by the WAF.
14-
// It should be handled differently than other errors to avoid leaking information to an attacker.
15-
// If this error was returned by native types wrapped by dd-trace-go, it means that a 403 response will be written
16-
// by appsec middleware (or any other status code defined in DataDog's UI). Therefore, the user should not write a
17-
// response in the handler.
12+
// BlockingSecurityEvent is the error type returned by function calls blocked by appsec.
13+
// Even though appsec takes care of responding automatically to the blocked requests, it
14+
// is your duty to abort the request handlers that are calling functions blocked by appsec.
15+
// For instance, if a gRPC handler performs a SQL query blocked by appsec, the SQL query
16+
// function call gets blocked and aborted by returning an error of type SecurityBlockingEvent.
17+
// This allows you to safely abort your request handlers, and to be able to leverage errors.As if
18+
// necessary in your Go error management logic to be able to tell if the error is a blocking security
19+
// event or not (eg. to avoid retrying an HTTP client request).
1820
type BlockingSecurityEvent struct{}
1921

2022
func (*BlockingSecurityEvent) Error() string {

Diff for: internal/appsec/emitter/httpsec/roundtripper.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func ProtectRoundTrip(ctx context.Context, url string) error {
2626
parent, _ := ctx.Value(listener.ContextKey{}).(dyngo.Operation)
2727
if parent == nil { // No parent operation => we can't monitor the request
2828
badInputContextOnce.Do(func() {
29-
log.Debug("appsec: outgoing http request monitoring ignored: could not find the http handler " +
29+
log.Debug("appsec: outgoing http request monitoring ignored: could not find the handler " +
3030
"instrumentation metadata in the request context: the request handler is not being monitored by a " +
3131
"middleware function or the incoming request context has not be forwarded correctly to the roundtripper")
3232
})

Diff for: internal/appsec/emitter/httpsec/types/types.go

+3
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,13 @@ type (
7676
// SDKBodyOperationRes is the SDK body operation results.
7777
SDKBodyOperationRes struct{}
7878

79+
// RoundTripOperationArgs is the round trip operation arguments.
7980
RoundTripOperationArgs struct {
81+
// URL corresponds to the address `server.io.net.url`.
8082
URL string
8183
}
8284

85+
// RoundTripOperationRes is the round trip operation results.
8386
RoundTripOperationRes struct{}
8487
)
8588

Diff for: internal/appsec/listener/httpsec/roundtripper.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"gopkg.in/DataDog/dd-trace-go.v1/internal/log"
1616
)
1717

18-
// RegisterRoundTripperListener registers a listener on outgoing requests to run the WAF.
18+
// RegisterRoundTripperListener registers a listener on outgoing HTTP client requests to run the WAF.
1919
func RegisterRoundTripperListener(op dyngo.Operation, events *trace.SecurityEventsHolder, wafCtx *waf.Context, limiter limiter.Limiter) {
2020
dyngo.On(op, func(op *types.RoundTripOperation, args types.RoundTripOperationArgs) {
2121
wafResult := sharedsec.RunWAF(wafCtx, waf.RunAddressData{Persistent: map[string]any{ServerIoNetURLAddr: args.URL}})

0 commit comments

Comments
 (0)