crowdsec/pkg/waf/env.go

42 lines
1.2 KiB
Go
Raw Normal View History

2023-07-04 15:36:56 +00:00
package waf
2023-09-11 08:35:14 +00:00
import (
"github.com/crowdsecurity/coraza/v3"
"github.com/crowdsecurity/coraza/v3/experimental"
)
2023-07-04 15:36:56 +00:00
2023-09-11 08:35:14 +00:00
type ExtendedTransaction struct {
2023-07-04 15:36:56 +00:00
Tx experimental.FullTransaction
}
2023-09-11 08:35:14 +00:00
func NewExtendedTransaction(engine coraza.WAF, uuid string) ExtendedTransaction {
inBoundTx := engine.NewTransactionWithID(uuid)
expTx := inBoundTx.(experimental.FullTransaction)
tx := NewTransaction(expTx)
return tx
2023-07-04 15:36:56 +00:00
}
2023-09-11 08:35:14 +00:00
func NewTransaction(tx experimental.FullTransaction) ExtendedTransaction {
return ExtendedTransaction{Tx: tx}
}
func (t *ExtendedTransaction) RemoveRuleByIDWithError(id int) error {
2023-07-04 15:36:56 +00:00
t.Tx.RemoveRuleByID(id)
return nil
}
2023-09-13 15:12:09 +00:00
// simply used to ease the compilation & runtime of the hooks
func GetHookEnv(w WaapRuntimeConfig, request ParsedRequest) map[string]interface{} {
2023-07-04 15:36:56 +00:00
return map[string]interface{}{
2023-09-13 15:12:09 +00:00
"inband_rules": w.InBandRules,
"outband_rules": w.OutOfBandRules,
"req": request,
"RemoveInbandRuleByID": w.RemoveInbandRuleByID,
"RemoveOutbandRuleByID": w.RemoveOutbandRuleByID,
"SetAction": w.SetAction,
"SetHTTPCode": w.SetHTTPCode,
"SetActionByID": w.SetActionnByID,
"CancelEvent": w.CancelEvent,
2023-07-04 15:36:56 +00:00
}
}