21
21
/* Those are defined twice, lets keep it defined just once by `undef`
22
22
* the first one.
23
23
*/
24
+ * /
24
25
#undef CR
25
26
#undef LF
26
27
#undef CRLF
@@ -228,7 +229,6 @@ ngx_pstrdup0(ngx_pool_t *pool, ngx_str_t *src)
228
229
return dst ;
229
230
}
230
231
231
-
232
232
/*
233
233
* MultiplyDeBruijnBitPosition
234
234
* http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightMultLookup
@@ -563,6 +563,10 @@ ngx_http_modsecurity_load_request_body(ngx_http_request_t *r)
563
563
ngx_http_modsecurity_ctx_t * ctx ;
564
564
ngx_chain_t * chain ;
565
565
566
+ ngx_log_debug (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
567
+ "ModSec: loading request body." );
568
+
569
+
566
570
ngx_log_debug (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
567
571
"ModSec: loading request body." );
568
572
@@ -598,7 +602,6 @@ ngx_http_modsecurity_load_request_body(ngx_http_request_t *r)
598
602
599
603
return NGX_OK ;
600
604
}
601
-
602
605
static ngx_inline ngx_int_t
603
606
ngx_http_modsecurity_save_request_body (ngx_http_request_t * r )
604
607
{
@@ -607,7 +610,6 @@ ngx_http_modsecurity_save_request_body(ngx_http_request_t *r)
607
610
apr_off_t content_length ;
608
611
ngx_buf_t * buf ;
609
612
#endif
610
-
611
613
ctx = ngx_http_get_module_ctx (r , ngx_http_modsecurity );
612
614
613
615
#ifdef MOVE_REQUEST_CHAIN_TO_MODSEC
@@ -619,10 +621,8 @@ ngx_http_modsecurity_save_request_body(ngx_http_request_t *r)
619
621
apr_brigade_cleanup (ctx -> brigade );
620
622
buf -> last += content_length ;
621
623
r -> header_in = buf ;
622
-
623
624
if (r -> headers_in .content_length ) {
624
625
ngx_str_t * str = NULL ;
625
-
626
626
str = & r -> headers_in .content_length -> value ;
627
627
str -> data = ngx_palloc (r -> pool , NGX_OFF_T_LEN );
628
628
if (str -> data == NULL ) {
@@ -631,18 +631,31 @@ ngx_http_modsecurity_save_request_body(ngx_http_request_t *r)
631
631
}
632
632
str -> len = ngx_snprintf (str -> data , NGX_OFF_T_LEN , "%O" ,
633
633
content_length ) - str -> data ;
634
-
635
- }
636
-
637
634
r -> headers_in .content_length_n = content_length ;
638
-
639
635
ngx_log_debug (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
640
636
"ModSec: Content length: %O, Content length n: %O" , content_length ,
641
637
r -> headers_in .content_length_n );
642
638
#else
643
639
apr_brigade_cleanup (ctx -> brigade );
644
640
#endif
645
641
642
+ if (r -> headers_in .content_length ) {
643
+ ngx_str_t * str = NULL ;
644
+
645
+ str = & r -> headers_in .content_length -> value ;
646
+ str -> data = ngx_palloc (r -> pool , NGX_OFF_T_LEN );
647
+ if (str -> data == NULL ) {
648
+ ngx_http_finalize_request (r , NGX_HTTP_INTERNAL_SERVER_ERROR );
649
+ return NGX_OK ;
650
+ }
651
+ str -> len = ngx_snprintf (str -> data , NGX_OFF_T_LEN , "%O" , content_length ) - str -> data ;
652
+
653
+ }
654
+
655
+
656
+ r -> headers_in .content_length_n = content_length ;
657
+
658
+ ngx_log_debug (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 , "ModSec: Content length: %O, Content length n: %O" , content_length , r -> headers_in .content_length_n );
646
659
return NGX_OK ;
647
660
}
648
661
@@ -1151,19 +1164,25 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r) {
1151
1164
ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1152
1165
"ModSec: ModSecurity is not enabled or not a main request." );
1153
1166
1167
+ ctx = ngx_http_modsecurity_create_ctx (r );
1168
+
1154
1169
return NGX_DECLINED ;
1170
+ if (ngx_http_set_pool_ctx (r , ctx , ngx_http_modsecurity ) != NGX_OK ) {
1171
+ return NGX_ERROR ;
1155
1172
}
1156
1173
1157
1174
ctx = ngx_http_get_module_ctx (r , ngx_http_modsecurity );
1158
1175
1159
1176
ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1160
1177
"ModSec: Recovering ctx: %p" , ctx );
1178
+ ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1179
+ "ModSec: ctx is null, nothing we can do, returning." );
1161
1180
1162
1181
if (ctx == NULL ) {
1163
1182
ctx = ngx_http_modsecurity_create_ctx (r );
1164
1183
1165
1184
ngx_http_set_ctx (r , ctx , ngx_http_modsecurity );
1166
-
1185
+ "ModSec: ctx is now: %p / count: %d" , ctx , r -> main -> count );
1167
1186
if (ngx_http_set_pool_ctx (r , ctx , ngx_http_modsecurity ) != NGX_OK ) {
1168
1187
return NGX_ERROR ;
1169
1188
}
@@ -1181,19 +1200,17 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r) {
1181
1200
ngx_log_debug2 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1182
1201
"ModSec: ctx is now: %p / count: %d" , ctx , r -> main -> count );
1183
1202
1184
- if (modsecContextState (ctx -> req ) == MODSEC_DISABLED ) {
1185
1203
ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1186
1204
"ModSec: ModSecurity was disabled, returning...." , ctx );
1187
1205
1188
- return NGX_DECLINED ;
1189
- }
1190
1206
if (ctx -> waiting_more_body == 1 ) {
1191
1207
ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1192
1208
"ModSec: waiting for more data before proceed. / count: %d" ,
1193
1209
r -> main -> count );
1194
1210
1195
1211
return NGX_DONE ;
1196
1212
}
1213
+ ngx_http_modsecurity_request_read );
1197
1214
1198
1215
if (ctx -> body_requested == 0 ) {
1199
1216
ngx_log_debug (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
@@ -1221,9 +1238,16 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r) {
1221
1238
1222
1239
ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1223
1240
"ModSec: request is ready to be processed." );
1224
- rc = ngx_http_modsecurity_process_request (r );
1241
+ ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1242
+ "ModSec: chuncked? %d" , r -> chunked );
1243
+ ngx_http_modsecurity_process_request (r );
1225
1244
ctx -> request_processed = 1 ;
1245
+ }
1226
1246
1247
+ ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1248
+ "ModSec: request is ready to be processed." );
1249
+ rc = ngx_http_modsecurity_process_request (r );
1250
+ ctx -> request_processed = 1 ;
1227
1251
if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE ) {
1228
1252
ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1229
1253
"ModSec: returning a special response after process " \
@@ -1232,8 +1256,10 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r) {
1232
1256
return rc ;
1233
1257
}
1234
1258
1259
+ void
1260
+ ngx_http_modsecurity_request_read (ngx_http_request_t * r )
1261
+ {
1235
1262
1236
- }
1237
1263
1238
1264
ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1239
1265
"ModSec: returning NGX_DECLINED." );
@@ -1435,7 +1461,7 @@ ngx_http_modsecurity_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
1435
1461
}
1436
1462
1437
1463
return ngx_http_next_body_filter (r , out );
1438
-
1464
+ #endif
1439
1465
return NGX_OK ;
1440
1466
}
1441
1467
#endif
0 commit comments