expose internal coraza vars in evt.Waap

This commit is contained in:
Sebastien Blot 2023-07-27 10:01:56 +02:00
parent 2f5a6fbb4f
commit dd5e38a2c5
No known key found for this signature in database
GPG key ID: DFC2902F40449F6A
2 changed files with 17 additions and 12 deletions

View file

@ -74,8 +74,22 @@ func (r *WafRunner) AccumulateTxToEvent(tx experimental.FullTransaction, kind st
evt.Meta["waap_action"] = tx.Interruption().Action evt.Meta["waap_action"] = tx.Interruption().Action
} }
if evt.Waap.Vars == nil {
evt.Waap.Vars = map[string]string{}
}
tx.Variables().All(func(v variables.RuleVariable, col collection.Collection) bool { tx.Variables().All(func(v variables.RuleVariable, col collection.Collection) bool {
for _, variable := range col.FindAll() { for _, variable := range col.FindAll() {
key := ""
if variable.Key() == "" {
key = variable.Variable().Name()
} else {
key = variable.Variable().Name() + "." + variable.Key()
}
if variable.Value() == "" {
continue
}
evt.Waap.Vars[key] = variable.Value()
r.logger.Infof("%s.%s = %s", variable.Variable().Name(), variable.Key(), variable.Value()) r.logger.Infof("%s.%s = %s", variable.Variable().Name(), variable.Key(), variable.Value())
} }
return true return true

View file

@ -3,7 +3,6 @@ package types
import ( import (
"fmt" "fmt"
"regexp" "regexp"
"strings"
"time" "time"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@ -58,18 +57,10 @@ func (w WaapEvent) GetVar(varName string) string {
if w.Vars == nil { if w.Vars == nil {
return "" return ""
} }
parsed := strings.Split(varName, ".") if val, ok := w.Vars[varName]; ok {
if len(parsed) == 1 { return val
//no subkey
return w.Vars[varName]
} else if len(parsed) == 2 {
//subkey
if w.Vars[parsed[0]] == "" {
return ""
}
//return w.Vars[parsed[0]][parsed[1]]
} }
log.Warningf("invalid variable name %s", varName) log.Infof("var %s not found", varName, w.Vars)
return "" return ""
} }