-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
urlencoded.go
48 lines (39 loc) · 1.23 KB
/
urlencoded.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
// Copyright 2022 Juan Pablo Tosso and the OWASP Coraza contributors
// SPDX-License-Identifier: Apache-2.0
package bodyprocessors
import (
"io"
"strconv"
"strings"
"github.com/appsentinels/coraza/v3/experimental/plugins/plugintypes"
"github.com/appsentinels/coraza/v3/internal/collections"
"github.com/appsentinels/coraza/v3/internal/url"
)
type urlencodedBodyProcessor struct {
}
func (*urlencodedBodyProcessor) ProcessRequest(reader io.Reader, v plugintypes.TransactionVariables, options plugintypes.BodyProcessorOptions) error {
buf := new(strings.Builder)
if _, err := io.Copy(buf, reader); err != nil {
return err
}
b := buf.String()
values := url.ParseQuery(b, '&')
argsCol := v.ArgsPost()
for k, vs := range values {
argsCol.Set(k, vs)
}
v.RequestBody().(*collections.Single).Set(b)
v.RequestBodyLength().(*collections.Single).Set(strconv.Itoa(len(b)))
return nil
}
func (*urlencodedBodyProcessor) ProcessResponse(reader io.Reader, v plugintypes.TransactionVariables, options plugintypes.BodyProcessorOptions) error {
return nil
}
var (
_ plugintypes.BodyProcessor = &urlencodedBodyProcessor{}
)
func init() {
RegisterBodyProcessor("urlencoded", func() plugintypes.BodyProcessor {
return &urlencodedBodyProcessor{}
})
}