@@ -228,6 +228,7 @@ ngx_pstrdup0(ngx_pool_t *pool, ngx_str_t *src)
228
228
return dst ;
229
229
}
230
230
231
+
231
232
/*
232
233
* MultiplyDeBruijnBitPosition
233
234
* http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightMultLookup
@@ -565,9 +566,6 @@ ngx_http_modsecurity_load_request_body(ngx_http_request_t *r)
565
566
ngx_http_modsecurity_ctx_t * ctx ;
566
567
ngx_chain_t * chain ;
567
568
568
- ngx_log_debug (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
569
- "ModSec: loading request body." );
570
-
571
569
ngx_log_debug (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
572
570
"ModSec: loading request body." );
573
571
@@ -601,12 +599,9 @@ ngx_http_modsecurity_load_request_body(ngx_http_request_t *r)
601
599
}
602
600
#endif
603
601
604
- return NGX_ERROR ;
605
- }
606
- #endif
607
-
608
602
return NGX_OK ;
609
603
}
604
+
610
605
static ngx_inline ngx_int_t
611
606
ngx_http_modsecurity_save_request_body (ngx_http_request_t * r )
612
607
{
@@ -627,23 +622,6 @@ ngx_http_modsecurity_save_request_body(ngx_http_request_t *r)
627
622
apr_brigade_cleanup (ctx -> brigade );
628
623
buf -> last += content_length ;
629
624
r -> header_in = buf ;
630
- if (r -> headers_in .content_length ) {
631
- ngx_str_t * str = NULL ;
632
- str = & r -> headers_in .content_length -> value ;
633
- str -> data = ngx_palloc (r -> pool , NGX_OFF_T_LEN );
634
- if (str -> data == NULL ) {
635
- ngx_http_finalize_request (r , NGX_HTTP_INTERNAL_SERVER_ERROR );
636
- return NGX_OK ;
637
- }
638
- str -> len = ngx_snprintf (str -> data , NGX_OFF_T_LEN , "%O" ,
639
- content_length ) - str -> data ;
640
- r -> headers_in .content_length_n = content_length ;
641
- ngx_log_debug (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
642
- "ModSec: Content length: %O, Content length n: %O" , content_length ,
643
- r -> headers_in .content_length_n );
644
- #else
645
- apr_brigade_cleanup (ctx -> brigade );
646
- #endif
647
625
648
626
if (r -> headers_in .content_length ) {
649
627
ngx_str_t * str = NULL ;
@@ -1170,25 +1148,19 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r) {
1170
1148
ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1171
1149
"ModSec: ModSecurity is not enabled or not a main request." );
1172
1150
1173
- ctx = ngx_http_modsecurity_create_ctx (r );
1174
-
1175
1151
return NGX_DECLINED ;
1176
- if (ngx_http_set_pool_ctx (r , ctx , ngx_http_modsecurity ) != NGX_OK ) {
1177
- return NGX_ERROR ;
1178
1152
}
1179
1153
1180
1154
ctx = ngx_http_get_module_ctx (r , ngx_http_modsecurity );
1181
1155
1182
1156
ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1183
1157
"ModSec: Recovering ctx: %p" , ctx );
1184
- ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1185
- "ModSec: ctx is null, nothing we can do, returning." );
1186
1158
1187
1159
if (ctx == NULL ) {
1188
1160
ctx = ngx_http_modsecurity_create_ctx (r );
1189
1161
1190
1162
ngx_http_set_ctx (r , ctx , ngx_http_modsecurity );
1191
- "ModSec: ctx is now: %p / count: %d" , ctx , r -> main -> count );
1163
+
1192
1164
if (ngx_http_set_pool_ctx (r , ctx , ngx_http_modsecurity ) != NGX_OK ) {
1193
1165
return NGX_ERROR ;
1194
1166
}
@@ -1206,17 +1178,19 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r) {
1206
1178
ngx_log_debug2 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1207
1179
"ModSec: ctx is now: %p / count: %d" , ctx , r -> main -> count );
1208
1180
1181
+ if (modsecContextState (ctx -> req ) == MODSEC_DISABLED ) {
1209
1182
ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1210
1183
"ModSec: ModSecurity was disabled, returning...." , ctx );
1211
1184
1185
+ return NGX_DECLINED ;
1186
+ }
1212
1187
if (ctx -> waiting_more_body == 1 ) {
1213
1188
ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1214
1189
"ModSec: waiting for more data before proceed. / count: %d" ,
1215
1190
r -> main -> count );
1216
1191
1217
1192
return NGX_DONE ;
1218
1193
}
1219
- ngx_http_modsecurity_request_read );
1220
1194
1221
1195
if (ctx -> body_requested == 0 ) {
1222
1196
ngx_log_debug (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
@@ -1258,23 +1232,6 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r) {
1258
1232
1259
1233
}
1260
1234
1261
- ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1262
- "ModSec: request is ready to be processed." );
1263
- rc = ngx_http_modsecurity_process_request (r );
1264
- ctx -> request_processed = 1 ;
1265
- if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE ) {
1266
- ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1267
- "ModSec: returning a special response after process " \
1268
- "a request: %d" , rc );
1269
-
1270
- return rc ;
1271
- }
1272
-
1273
- void
1274
- ngx_http_modsecurity_request_read (ngx_http_request_t * r )
1275
- {
1276
-
1277
-
1278
1235
ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1279
1236
"ModSec: returning NGX_DECLINED." );
1280
1237
@@ -1475,7 +1432,7 @@ ngx_http_modsecurity_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
1475
1432
}
1476
1433
1477
1434
return ngx_http_next_body_filter (r , out );
1478
- #endif
1435
+
1479
1436
return NGX_OK ;
1480
1437
}
1481
1438
#endif
0 commit comments