1
1
package plugin
2
2
3
3
import (
4
+ "bytes"
4
5
"context"
5
6
"encoding/base64"
6
7
"encoding/json"
7
- "fmt"
8
8
"net/http"
9
+ "net/url"
9
10
10
11
"github.com/corazawaf/libinjection-go"
11
12
tf "github.com/galeone/tensorflow/tensorflow/go"
@@ -27,6 +28,7 @@ type Plugin struct {
27
28
Threshold float32
28
29
EnableLibinjection bool
29
30
LibinjectionPermissiveMode bool
31
+ APIAddress string
30
32
}
31
33
32
34
type InjectionDetectionPlugin struct {
@@ -144,9 +146,27 @@ func (p *Plugin) OnTrafficFromClient(ctx context.Context, req *v1.Struct) (*v1.S
144
146
return req
145
147
}
146
148
147
- // Make an HTTP GET request to the tokenize service.
148
- resp , err := http .Get (
149
- fmt .Sprintf ("http://localhost:5000/tokenize_and_sequence/%s" , queryString ))
149
+ // Create a JSON body for the request.
150
+ body , err := json .Marshal (map [string ]interface {}{
151
+ "query" : queryString ,
152
+ })
153
+ if err != nil {
154
+ p .Logger .Error ("Failed to marshal body" , "error" , err )
155
+ if isSQLi (queryString ) && ! p .LibinjectionPermissiveMode {
156
+ return errorResponse (), nil
157
+ }
158
+ return req , nil
159
+ }
160
+ // Make an HTTP POST request to the tokenize service.
161
+ tokenizeEndpoint , err := url .JoinPath (p .APIAddress , "/tokenize_and_sequence" )
162
+ if err != nil {
163
+ p .Logger .Error ("Failed to join API address and path" , "error" , err )
164
+ if isSQLi (queryString ) && ! p .LibinjectionPermissiveMode {
165
+ return errorResponse (), nil
166
+ }
167
+ return req , nil
168
+ }
169
+ resp , err := http .Post (tokenizeEndpoint , "application/json" , bytes .NewBuffer (body ))
150
170
if err != nil {
151
171
p .Logger .Error ("Failed to make GET request" , "error" , err )
152
172
if isSQLi (queryString ) && ! p .LibinjectionPermissiveMode {
0 commit comments