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,17 @@ 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
+ r -> headers_in .content_length_n = content_length ;
643
+
644
+ 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
645
return NGX_OK ;
647
646
}
648
647
@@ -1145,19 +1144,25 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r) {
1145
1144
ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1146
1145
"ModSec: ModSecurity is not enabled or not a main request." );
1147
1146
1147
+ ctx = ngx_http_modsecurity_create_ctx (r );
1148
+
1148
1149
return NGX_DECLINED ;
1150
+ if (ngx_http_set_pool_ctx (r , ctx , ngx_http_modsecurity ) != NGX_OK ) {
1151
+ return NGX_ERROR ;
1149
1152
}
1150
1153
1151
1154
ctx = ngx_http_get_module_ctx (r , ngx_http_modsecurity );
1152
1155
1153
1156
ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1154
1157
"ModSec: Recovering ctx: %p" , ctx );
1158
+ ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1159
+ "ModSec: ctx is null, nothing we can do, returning." );
1155
1160
1156
1161
if (ctx == NULL ) {
1157
1162
ctx = ngx_http_modsecurity_create_ctx (r );
1158
1163
1159
1164
ngx_http_set_ctx (r , ctx , ngx_http_modsecurity );
1160
-
1165
+ "ModSec: ctx is now: %p / count: %d" , ctx , r -> main -> count );
1161
1166
if (ngx_http_set_pool_ctx (r , ctx , ngx_http_modsecurity ) != NGX_OK ) {
1162
1167
return NGX_ERROR ;
1163
1168
}
@@ -1175,19 +1180,17 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r) {
1175
1180
ngx_log_debug2 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1176
1181
"ModSec: ctx is now: %p / count: %d" , ctx , r -> main -> count );
1177
1182
1178
- if (modsecContextState (ctx -> req ) == MODSEC_DISABLED ) {
1179
1183
ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1180
1184
"ModSec: ModSecurity was disabled, returning...." , ctx );
1181
1185
1182
- return NGX_DECLINED ;
1183
- }
1184
1186
if (ctx -> waiting_more_body == 1 ) {
1185
1187
ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1186
1188
"ModSec: waiting for more data before proceed. / count: %d" ,
1187
1189
r -> main -> count );
1188
1190
1189
1191
return NGX_DONE ;
1190
1192
}
1193
+ ngx_http_modsecurity_request_read );
1191
1194
1192
1195
if (ctx -> body_requested == 0 ) {
1193
1196
ngx_log_debug (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
@@ -1212,12 +1215,16 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r) {
1212
1215
}
1213
1216
1214
1217
if (ctx -> waiting_more_body == 0 && ctx -> request_processed == 0 ) {
1218
+ ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1219
+ "ModSec: request is ready to be processed." );
1220
+ ngx_http_modsecurity_process_request (r );
1221
+ ctx -> request_processed = 1 ;
1222
+ }
1215
1223
1216
1224
ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1217
1225
"ModSec: request is ready to be processed." );
1218
1226
rc = ngx_http_modsecurity_process_request (r );
1219
1227
ctx -> request_processed = 1 ;
1220
-
1221
1228
if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE ) {
1222
1229
ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1223
1230
"ModSec: returning a special response after process " \
@@ -1226,8 +1233,10 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r) {
1226
1233
return rc ;
1227
1234
}
1228
1235
1236
+ void
1237
+ ngx_http_modsecurity_request_read (ngx_http_request_t * r )
1238
+ {
1229
1239
1230
- }
1231
1240
1232
1241
ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1233
1242
"ModSec: returning NGX_DECLINED." );
@@ -1429,7 +1438,7 @@ ngx_http_modsecurity_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
1429
1438
}
1430
1439
1431
1440
return ngx_http_next_body_filter (r , out );
1432
-
1441
+ #endif
1433
1442
return NGX_OK ;
1434
1443
}
1435
1444
#endif
0 commit comments