-
-
Notifications
You must be signed in to change notification settings - Fork 242
/
Copy pathmsg.go
52 lines (43 loc) · 1.38 KB
/
msg.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2022 Juan Pablo Tosso and the OWASP Coraza contributors
// SPDX-License-Identifier: Apache-2.0
package actions
import (
"github.com/corazawaf/coraza/v3/experimental/plugins/macro"
"github.com/corazawaf/coraza/v3/experimental/plugins/plugintypes"
"github.com/corazawaf/coraza/v3/internal/corazawaf"
utils "github.com/corazawaf/coraza/v3/internal/strings"
)
// Action Group: Metadata
//
// Description:
// Assigns a custom message to the rule or chain in which it appears, and the message will be logged along with every alert.
// Noted that the msg information appears in the error and/or audit log files and is not sent back to the client in response headers.
//
// Example:
// ```
// SecRule &REQUEST_HEADERS:Host "@eq 0" "log,id:60008,severity:2,msg:'Request Missing a Host Header'"
// ```
type msgFn struct{}
func (a *msgFn) Init(r plugintypes.RuleMetadata, data string) error {
data = utils.MaybeRemoveQuotes(data)
if len(data) == 0 {
return ErrMissingArguments
}
msg, err := macro.NewMacro(data)
if err != nil {
return err
}
r.(*corazawaf.Rule).Msg = msg
return nil
}
func (a *msgFn) Evaluate(_ plugintypes.RuleMetadata, _ plugintypes.TransactionState) {}
func (a *msgFn) Type() plugintypes.ActionType {
return plugintypes.ActionTypeMetadata
}
func msg() plugintypes.Action {
return &msgFn{}
}
var (
_ plugintypes.Action = &msgFn{}
_ ruleActionWrapper = msg
)