@@ -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 ;
@@ -1176,25 +1154,19 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r) {
1176
1154
ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1177
1155
"ModSec: ModSecurity is not enabled or not a main request." );
1178
1156
1179
- ctx = ngx_http_modsecurity_create_ctx (r );
1180
-
1181
1157
return NGX_DECLINED ;
1182
- if (ngx_http_set_pool_ctx (r , ctx , ngx_http_modsecurity ) != NGX_OK ) {
1183
- return NGX_ERROR ;
1184
1158
}
1185
1159
1186
1160
ctx = ngx_http_get_module_ctx (r , ngx_http_modsecurity );
1187
1161
1188
1162
ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1189
1163
"ModSec: Recovering ctx: %p" , ctx );
1190
- ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1191
- "ModSec: ctx is null, nothing we can do, returning." );
1192
1164
1193
1165
if (ctx == NULL ) {
1194
1166
ctx = ngx_http_modsecurity_create_ctx (r );
1195
1167
1196
1168
ngx_http_set_ctx (r , ctx , ngx_http_modsecurity );
1197
- "ModSec: ctx is now: %p / count: %d" , ctx , r -> main -> count );
1169
+
1198
1170
if (ngx_http_set_pool_ctx (r , ctx , ngx_http_modsecurity ) != NGX_OK ) {
1199
1171
return NGX_ERROR ;
1200
1172
}
@@ -1212,17 +1184,19 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r) {
1212
1184
ngx_log_debug2 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1213
1185
"ModSec: ctx is now: %p / count: %d" , ctx , r -> main -> count );
1214
1186
1187
+ if (modsecContextState (ctx -> req ) == MODSEC_DISABLED ) {
1215
1188
ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1216
1189
"ModSec: ModSecurity was disabled, returning...." , ctx );
1217
1190
1191
+ return NGX_DECLINED ;
1192
+ }
1218
1193
if (ctx -> waiting_more_body == 1 ) {
1219
1194
ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1220
1195
"ModSec: waiting for more data before proceed. / count: %d" ,
1221
1196
r -> main -> count );
1222
1197
1223
1198
return NGX_DONE ;
1224
1199
}
1225
- ngx_http_modsecurity_request_read );
1226
1200
1227
1201
if (ctx -> body_requested == 0 ) {
1228
1202
ngx_log_debug (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
@@ -1264,23 +1238,6 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r) {
1264
1238
1265
1239
}
1266
1240
1267
- ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1268
- "ModSec: request is ready to be processed." );
1269
- rc = ngx_http_modsecurity_process_request (r );
1270
- ctx -> request_processed = 1 ;
1271
- if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE ) {
1272
- ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1273
- "ModSec: returning a special response after process " \
1274
- "a request: %d" , rc );
1275
-
1276
- return rc ;
1277
- }
1278
-
1279
- void
1280
- ngx_http_modsecurity_request_read (ngx_http_request_t * r )
1281
- {
1282
-
1283
-
1284
1241
ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1285
1242
"ModSec: returning NGX_DECLINED." );
1286
1243
@@ -1481,7 +1438,7 @@ ngx_http_modsecurity_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
1481
1438
}
1482
1439
1483
1440
return ngx_http_next_body_filter (r , out );
1484
- #endif
1441
+
1485
1442
return NGX_OK ;
1486
1443
}
1487
1444
#endif
0 commit comments