Skip to content

Commit

Permalink
Fix error callback registration (envoyproxy#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
nacx authored Jan 11, 2023
1 parent f31da90 commit 52264b5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/corazawaf/coraza-proxy-wasm
go 1.19

require (
github.com/corazawaf/coraza/v3 v3.0.0-20221228061051-6da83a9c51ad
github.com/corazawaf/coraza/v3 v3.0.0-20230110223518-703d29668893
github.com/stretchr/testify v1.8.0
github.com/tetratelabs/proxy-wasm-go-sdk v0.20.1-0.20221031045735-89d180d022a5
github.com/tidwall/gjson v1.14.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/corazawaf/coraza/v3 v3.0.0-20221228061051-6da83a9c51ad h1:mgff0DXbe96GPGog+1pO924N292NmsMwk5yFxLPgCd8=
github.com/corazawaf/coraza/v3 v3.0.0-20221228061051-6da83a9c51ad/go.mod h1:SMJQI/wT4xkDyCPnt6LN3q8bnci/VXhq7IglfW5isOM=
github.com/corazawaf/coraza/v3 v3.0.0-20230110223518-703d29668893 h1:ARMfbunvqZfXCphuTMiG7RWDBbCOOTRygJbQGJwQMWA=
github.com/corazawaf/coraza/v3 v3.0.0-20230110223518-703d29668893/go.mod h1:SMJQI/wT4xkDyCPnt6LN3q8bnci/VXhq7IglfW5isOM=
github.com/corazawaf/libinjection-go v0.1.1 h1:N/SMuy9Q4wPL72pU/OsoYjIIjfvUbsVwHf8A3tWMLKg=
github.com/corazawaf/libinjection-go v0.1.1/go.mod h1:OP4TM7xdJ2skyXqNX1AN1wN5nNZEmJNuWbNPOItn7aw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
9 changes: 2 additions & 7 deletions wasmplugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func NewVMContext() types.VMContext {
return &vmContext{}
}

// Override types.DefaultVMContext.
func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext {
return &corazaPlugin{}
}
Expand All @@ -43,7 +42,6 @@ type corazaPlugin struct {
metrics *wafMetrics
}

// Override types.DefaultPluginContext.
func (ctx *corazaPlugin) OnPluginStart(pluginConfigurationSize int) types.OnPluginStartStatus {
data, err := proxywasm.GetPluginConfiguration()
if err != nil && err != types.ErrorStatusNotFound {
Expand All @@ -58,7 +56,7 @@ func (ctx *corazaPlugin) OnPluginStart(pluginConfigurationSize int) types.OnPlug

// First we initialize our waf and our seclang parser
conf := coraza.NewWAFConfig().
WithErrorLogger(logError).
WithErrorCallback(logError).
WithDebugLogger(&debugLogger{}).
WithRequestBodyAccess(coraza.NewRequestBodyConfig().
WithLimit(1024 * 1024 * 1024).
Expand All @@ -80,7 +78,6 @@ func (ctx *corazaPlugin) OnPluginStart(pluginConfigurationSize int) types.OnPlug
return types.OnPluginStartStatusOK
}

// Override types.DefaultPluginContext.
func (ctx *corazaPlugin) NewHttpContext(contextID uint32) types.HttpContext {
return &httpContext{
contextID: contextID,
Expand All @@ -105,7 +102,6 @@ type httpContext struct {
interruptionHandled bool
}

// Override types.DefaultHttpContext.
func (ctx *httpContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action {
defer logTime("OnHttpRequestHeaders", currentTime())

Expand Down Expand Up @@ -363,7 +359,6 @@ func (ctx *httpContext) OnHttpResponseBody(bodySize int, endOfStream bool) types
return types.ActionContinue
}

// Override types.DefaultHttpContext.
func (ctx *httpContext) OnHttpStreamDone() {
defer logTime("OnHttpStreamDone", currentTime())
tx := ctx.tx
Expand Down Expand Up @@ -435,7 +430,7 @@ func logError(error ctypes.MatchedRule) {
}
}

// Retrieves adddress properties from the proxy
// retrieveAddressInfo retrieves address properties from the proxy
// Expected targets are "source" or "destination"
// Envoy ref: https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes#connection-attributes
func retrieveAddressInfo(target string) (string, int) {
Expand Down

0 comments on commit 52264b5

Please sign in to comment.