@@ -238,6 +238,7 @@ ngx_http_modsecurity_create_ctx(ngx_http_request_t *r)
238
238
ngx_http_modsecurity_conf_t * loc_cf = NULL ;
239
239
ngx_http_modsecurity_conf_t * cf = NULL ;
240
240
ngx_pool_cleanup_t * cln = NULL ;
241
+ ngx_str_t s ;
241
242
242
243
ctx = ngx_pcalloc (r -> pool , sizeof (ngx_http_modsecurity_ctx_t ));
243
244
if (ctx == NULL )
@@ -250,7 +251,15 @@ ngx_http_modsecurity_create_ctx(ngx_http_request_t *r)
250
251
251
252
dd ("creating transaction with the following rules: '%p' -- ms: '%p'" , loc_cf -> rules_set , cf -> modsec );
252
253
253
- ctx -> modsec_transaction = msc_new_transaction (cf -> modsec , loc_cf -> rules_set , r -> connection -> log );
254
+ if (loc_cf -> transaction_id ) {
255
+ if (ngx_http_complex_value (r , loc_cf -> transaction_id , & s ) != NGX_OK ) {
256
+ return NGX_CONF_ERROR ;
257
+ }
258
+ ctx -> modsec_transaction = msc_new_transaction_with_id (cf -> modsec , loc_cf -> rules_set , (char * ) s .data , r -> connection -> log );
259
+
260
+ } else {
261
+ ctx -> modsec_transaction = msc_new_transaction (cf -> modsec , loc_cf -> rules_set , r -> connection -> log );
262
+ }
254
263
255
264
dd ("transaction created" );
256
265
@@ -352,6 +361,36 @@ char *ngx_conf_set_rules_remote(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
352
361
}
353
362
354
363
364
+ char * ngx_conf_set_transaction_id (ngx_conf_t * cf , ngx_command_t * cmd , void * conf ) {
365
+ ngx_str_t * value ;
366
+ ngx_http_complex_value_t cv ;
367
+ ngx_http_compile_complex_value_t ccv ;
368
+ ngx_http_modsecurity_conf_t * mcf = conf ;
369
+
370
+ value = cf -> args -> elts ;
371
+
372
+ ngx_memzero (& ccv , sizeof (ngx_http_compile_complex_value_t ));
373
+
374
+ ccv .cf = cf ;
375
+ ccv .value = & value [1 ];
376
+ ccv .complex_value = & cv ;
377
+ ccv .zero = 1 ;
378
+
379
+ if (ngx_http_compile_complex_value (& ccv ) != NGX_OK ) {
380
+ return NGX_CONF_ERROR ;
381
+ }
382
+
383
+ mcf -> transaction_id = ngx_palloc (cf -> pool , sizeof (ngx_http_complex_value_t ));
384
+ if (mcf -> transaction_id == NULL ) {
385
+ return NGX_CONF_ERROR ;
386
+ }
387
+
388
+ * mcf -> transaction_id = cv ;
389
+
390
+ return NGX_CONF_OK ;
391
+ }
392
+
393
+
355
394
static ngx_command_t ngx_http_modsecurity_commands [] = {
356
395
{
357
396
ngx_string ("modsecurity" ),
@@ -385,6 +424,14 @@ static ngx_command_t ngx_http_modsecurity_commands[] = {
385
424
offsetof(ngx_http_modsecurity_conf_t , enable ),
386
425
NULL
387
426
},
427
+ {
428
+ ngx_string ("modsecurity_transaction_id" ),
429
+ NGX_HTTP_LOC_CONF |NGX_HTTP_SRV_CONF |NGX_HTTP_MAIN_CONF |NGX_CONF_1MORE ,
430
+ ngx_conf_set_transaction_id ,
431
+ NGX_HTTP_LOC_CONF_OFFSET ,
432
+ 0 ,
433
+ NULL
434
+ },
388
435
ngx_null_command
389
436
};
390
437
@@ -542,19 +589,30 @@ static void *ngx_http_modsecurity_create_conf(ngx_conf_t *cf)
542
589
{
543
590
ngx_pool_cleanup_t * cln = NULL ;
544
591
ngx_http_modsecurity_conf_t * conf = (ngx_http_modsecurity_conf_t * )
545
- ngx_palloc (cf -> pool , sizeof (ngx_http_modsecurity_conf_t ));
592
+ ngx_pcalloc (cf -> pool , sizeof (ngx_http_modsecurity_conf_t ));
546
593
547
594
if (conf == NULL )
548
595
{
549
596
dd ("Failed to allocate space for ModSecurity configuration" );
550
597
return NGX_CONF_ERROR ;
551
598
}
552
599
600
+ /*
601
+ * set by ngx_pcalloc():
602
+ *
603
+ * conf->modsec = NULL;
604
+ * conf->enable = 0;
605
+ * conf->sanity_checks_enabled = 0;
606
+ * conf->rules_set = NULL;
607
+ * conf->pool = NULL;
608
+ * conf->transaction_id = NULL;
609
+ */
610
+
553
611
conf -> enable = NGX_CONF_UNSET ;
554
612
conf -> sanity_checks_enabled = NGX_CONF_UNSET ;
555
613
conf -> rules_set = msc_create_rules_set ();
556
- conf -> modsec = NULL ;
557
614
conf -> pool = cf -> pool ;
615
+ conf -> transaction_id = NGX_CONF_UNSET_PTR ;
558
616
559
617
cln = ngx_pool_cleanup_add (cf -> pool , 0 );
560
618
if (cln == NULL ) {
@@ -587,6 +645,7 @@ ngx_http_modsecurity_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
587
645
588
646
ngx_conf_merge_value (c -> enable , p -> enable , 0 );
589
647
ngx_conf_merge_value (c -> sanity_checks_enabled , p -> sanity_checks_enabled , 0 );
648
+ ngx_conf_merge_ptr_value (c -> transaction_id , p -> transaction_id , NULL );
590
649
591
650
#if defined(MODSECURITY_DDEBUG ) && (MODSECURITY_DDEBUG )
592
651
dd ("PARENT RULES" );
@@ -630,6 +689,7 @@ ngx_http_modsecurity_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
630
689
631
690
ngx_conf_merge_value (c -> enable , p -> enable , 0 );
632
691
ngx_conf_merge_value (c -> sanity_checks_enabled , p -> sanity_checks_enabled , 0 );
692
+ ngx_conf_merge_ptr_value (c -> transaction_id , p -> transaction_id , NULL );
633
693
634
694
#if defined(MODSECURITY_DDEBUG ) && (MODSECURITY_DDEBUG )
635
695
dd ("PARENT RULES" );
0 commit comments