From 52264b5df66128e5f96aea7e8cb6fc2ccff7b6e3 Mon Sep 17 00:00:00 2001 From: Ignasi Barrera Date: Thu, 12 Jan 2023 00:21:20 +0100 Subject: [PATCH] Fix error callback registration (#130) --- go.mod | 2 +- go.sum | 4 ++-- wasmplugin/plugin.go | 9 ++------- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 451dcc3c654d2..22ebdc534e71e 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 519d768ddd112..c81d7329f5c20 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/wasmplugin/plugin.go b/wasmplugin/plugin.go index f5ba08270c939..f0c1e90842e59 100644 --- a/wasmplugin/plugin.go +++ b/wasmplugin/plugin.go @@ -28,7 +28,6 @@ func NewVMContext() types.VMContext { return &vmContext{} } -// Override types.DefaultVMContext. func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext { return &corazaPlugin{} } @@ -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 { @@ -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). @@ -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, @@ -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()) @@ -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 @@ -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) {