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
|
2023-09-13 16:03:03 +00:00
|
|
|
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,
|
2023-09-19 06:54:31 +00:00
|
|
|
"SetActionByTag": w.SetActionByTag,
|
2023-09-13 15:12:09 +00:00
|
|
|
"SetHTTPCode": w.SetHTTPCode,
|
2023-09-19 06:54:31 +00:00
|
|
|
"SetActionByID": w.SetActionByID,
|
2023-09-13 15:12:09 +00:00
|
|
|
"CancelEvent": w.CancelEvent,
|
2023-10-04 12:17:21 +00:00
|
|
|
"IsInBand": request.IsInBand,
|
|
|
|
"IsOutBand": request.IsOutBand,
|
2023-07-04 15:36:56 +00:00
|
|
|
}
|
|
|
|
}
|