1
- use super :: { Extractor , HTTPRequestData , IsValid } ;
1
+ use super :: { Extractor , HttpRequestData , IsValid , RequestType } ;
2
2
3
3
use std:: collections:: hash_map:: Entry ;
4
4
use std:: collections:: HashMap ;
@@ -9,7 +9,7 @@ use aws_lambda_events::{
9
9
lambda_function_urls, s3, sns, sqs,
10
10
} ;
11
11
use bytes:: Buf ;
12
- use libddwaf:: object:: { WAFObject , WAFString } ;
12
+ use libddwaf:: object:: { WafObject , WafString } ;
13
13
use tracing:: debug;
14
14
15
15
/// Kong API Gateway events are a subset of [`apigw::ApiGatewayProxyRequest`].
@@ -49,8 +49,10 @@ impl IsValid for apigw::ApiGatewayProxyRequest {
49
49
&& !apigw:: ApiGatewayCustomAuthorizerRequestTypeRequest :: is_valid ( map)
50
50
}
51
51
}
52
- impl Extractor < ' _ > for apigw:: ApiGatewayProxyRequest {
53
- fn extract ( self ) -> HTTPRequestData {
52
+ impl Extractor for apigw:: ApiGatewayProxyRequest {
53
+ const TYPE : RequestType = RequestType :: APIGatewayV1 ;
54
+
55
+ fn extract ( self ) -> HttpRequestData {
54
56
let ( headers, cookies) = filter_headers ( self . multi_value_headers ) ;
55
57
56
58
// Headers are normalized to lowercase by [`filter_headers`].
@@ -61,7 +63,7 @@ impl Extractor<'_> for apigw::ApiGatewayProxyRequest {
61
63
. flatten ( )
62
64
} ) ;
63
65
64
- HTTPRequestData {
66
+ HttpRequestData {
65
67
source_ip : self . request_context . identity . source_ip . clone ( ) ,
66
68
route : self . resource ,
67
69
client_ip : self . request_context . identity . source_ip , // API Gateway exposes the Client IP as the Source IP
@@ -102,8 +104,10 @@ impl IsValid for apigw::ApiGatewayV2httpRequest {
102
104
}
103
105
}
104
106
}
105
- impl Extractor < ' _ > for apigw:: ApiGatewayV2httpRequest {
106
- fn extract ( self ) -> HTTPRequestData {
107
+ impl Extractor for apigw:: ApiGatewayV2httpRequest {
108
+ const TYPE : RequestType = RequestType :: APIGatewayV2Http ;
109
+
110
+ fn extract ( self ) -> HttpRequestData {
107
111
let ( headers, cookies) = filter_headers ( self . headers ) ;
108
112
109
113
let content_type = headers[ "content-type" ] . first ( ) . map ( String :: as_str) ;
@@ -113,7 +117,7 @@ impl Extractor<'_> for apigw::ApiGatewayV2httpRequest {
113
117
. flatten ( )
114
118
} ) ;
115
119
116
- HTTPRequestData {
120
+ HttpRequestData {
117
121
source_ip : self . request_context . http . source_ip . clone ( ) ,
118
122
route : self . route_key ,
119
123
client_ip : self . request_context . http . source_ip , // API Gateway exposes the Client IP as the Source IP
@@ -135,8 +139,10 @@ impl IsValid for KongAPIGatewayEvent {
135
139
&& matches ! ( map. get( "resource" ) , Some ( serde_json:: Value :: String ( _) ) )
136
140
}
137
141
}
138
- impl Extractor < ' _ > for KongAPIGatewayEvent {
139
- fn extract ( self ) -> HTTPRequestData {
142
+ impl Extractor for KongAPIGatewayEvent {
143
+ const TYPE : RequestType = RequestType :: APIGatewayV1 ;
144
+
145
+ fn extract ( self ) -> HttpRequestData {
140
146
self . 0 . extract ( )
141
147
}
142
148
}
@@ -153,8 +159,10 @@ impl IsValid for apigw::ApiGatewayWebsocketProxyRequest {
153
159
}
154
160
}
155
161
}
156
- impl Extractor < ' _ > for apigw:: ApiGatewayWebsocketProxyRequest {
157
- fn extract ( self ) -> HTTPRequestData {
162
+ impl Extractor for apigw:: ApiGatewayWebsocketProxyRequest {
163
+ const TYPE : RequestType = RequestType :: APIGatewayV2Websocket ;
164
+
165
+ fn extract ( self ) -> HttpRequestData {
158
166
let ( headers, cookies) = filter_headers ( self . multi_value_headers ) ;
159
167
160
168
let content_type = headers[ "content-type" ] . first ( ) . map ( String :: as_str) ;
@@ -164,7 +172,7 @@ impl Extractor<'_> for apigw::ApiGatewayWebsocketProxyRequest {
164
172
. flatten ( )
165
173
} ) ;
166
174
167
- HTTPRequestData {
175
+ HttpRequestData {
168
176
source_ip : self . request_context . identity . source_ip . clone ( ) ,
169
177
route : self . resource ,
170
178
client_ip : self . request_context . identity . source_ip , // API Gateway exposes the Client IP as the Source IP
@@ -194,9 +202,11 @@ impl IsValid for apigw::ApiGatewayCustomAuthorizerRequest {
194
202
}
195
203
}
196
204
}
197
- impl Extractor < ' _ > for apigw:: ApiGatewayCustomAuthorizerRequest {
198
- fn extract ( self ) -> HTTPRequestData {
199
- HTTPRequestData {
205
+ impl Extractor for apigw:: ApiGatewayCustomAuthorizerRequest {
206
+ const TYPE : RequestType = RequestType :: APIGatewayLambdaAuthorizerToken ;
207
+
208
+ fn extract ( self ) -> HttpRequestData {
209
+ HttpRequestData {
200
210
source_ip : None ,
201
211
route : None ,
202
212
client_ip : None ,
@@ -238,13 +248,15 @@ impl IsValid for apigw::ApiGatewayCustomAuthorizerRequestTypeRequest {
238
248
}
239
249
}
240
250
}
241
- impl Extractor < ' _ > for apigw:: ApiGatewayCustomAuthorizerRequestTypeRequest {
242
- fn extract ( self ) -> HTTPRequestData {
251
+ impl Extractor for apigw:: ApiGatewayCustomAuthorizerRequestTypeRequest {
252
+ const TYPE : RequestType = RequestType :: APIGatewayLambdaAuthorizerRequest ;
253
+
254
+ fn extract ( self ) -> HttpRequestData {
243
255
let source_ip = self . request_context . identity . and_then ( |i| i. source_ip ) ;
244
256
245
257
let ( headers, cookies) = filter_headers ( self . headers ) ;
246
258
247
- HTTPRequestData {
259
+ HttpRequestData {
248
260
source_ip : source_ip. clone ( ) ,
249
261
route : self . resource ,
250
262
client_ip : source_ip,
@@ -272,8 +284,10 @@ impl IsValid for alb::AlbTargetGroupRequest {
272
284
}
273
285
}
274
286
}
275
- impl Extractor < ' _ > for alb:: AlbTargetGroupRequest {
276
- fn extract ( self ) -> HTTPRequestData {
287
+ impl Extractor for alb:: AlbTargetGroupRequest {
288
+ const TYPE : RequestType = RequestType :: Alb ;
289
+
290
+ fn extract ( self ) -> HttpRequestData {
277
291
// Based on configuration, ALB provides headers EITHER in multi-value form OR in single-value form, never both.
278
292
let ( headers, cookies) = filter_headers ( if self . multi_value_headers . is_empty ( ) {
279
293
self . headers
@@ -294,7 +308,7 @@ impl Extractor<'_> for alb::AlbTargetGroupRequest {
294
308
. flatten ( )
295
309
} ) ;
296
310
297
- HTTPRequestData {
311
+ HttpRequestData {
298
312
source_ip : None ,
299
313
route : None ,
300
314
client_ip : None ,
@@ -375,8 +389,10 @@ impl IsValid for lambda_function_urls::LambdaFunctionUrlRequest {
375
389
}
376
390
}
377
391
}
378
- impl Extractor < ' _ > for lambda_function_urls:: LambdaFunctionUrlRequest {
379
- fn extract ( self ) -> HTTPRequestData {
392
+ impl Extractor for lambda_function_urls:: LambdaFunctionUrlRequest {
393
+ const TYPE : RequestType = RequestType :: LambdaFunctionUrl ;
394
+
395
+ fn extract ( self ) -> HttpRequestData {
380
396
let ( headers, cookies) = filter_headers ( self . headers ) ;
381
397
382
398
let content_type = headers[ "content-type" ] . first ( ) . map ( String :: as_str) ;
@@ -386,7 +402,7 @@ impl Extractor<'_> for lambda_function_urls::LambdaFunctionUrlRequest {
386
402
. flatten ( )
387
403
} ) ;
388
404
389
- HTTPRequestData {
405
+ HttpRequestData {
390
406
source_ip : self . request_context . http . source_ip . clone ( ) ,
391
407
route : None ,
392
408
client_ip : self . request_context . http . source_ip ,
@@ -458,7 +474,7 @@ fn parse_body(
458
474
body : impl AsRef < [ u8 ] > ,
459
475
is_base64_encoded : bool ,
460
476
content_type : Option < & str > ,
461
- ) -> Result < Option < WAFObject > , Box < dyn std:: error:: Error > > {
477
+ ) -> Result < Option < WafObject > , Box < dyn std:: error:: Error > > {
462
478
let body = body. as_ref ( ) ;
463
479
let reader: Box < dyn Read > = if is_base64_encoded {
464
480
Box :: new ( base64:: read:: DecoderReader :: new (
@@ -481,7 +497,7 @@ fn parse_body(
481
497
( mime:: APPLICATION , mime:: WWW_FORM_URLENCODED ) => todo ! ( ) ,
482
498
( mime:: APPLICATION | mime:: TEXT , mime:: XML ) => todo ! ( ) ,
483
499
( mime:: MULTIPART , mime:: FORM_DATA ) => todo ! ( ) ,
484
- ( mime:: TEXT , mime:: PLAIN ) => Some ( WAFString :: new ( body) . into ( ) ) ,
500
+ ( mime:: TEXT , mime:: PLAIN ) => Some ( WafString :: new ( body) . into ( ) ) ,
485
501
_ => {
486
502
debug ! ( "appsec: unsupported content type: {mime_type}" ) ;
487
503
None
0 commit comments