70
70
71
71
typedef struct {
72
72
ngx_flag_t enable ;
73
+ ngx_flag_t x_headers ;
73
74
directory_config * config ;
74
75
75
76
ngx_str_t * file ;
@@ -158,6 +159,12 @@ static ngx_command_t ngx_http_modsecurity_commands[] = {
158
159
NGX_HTTP_LOC_CONF_OFFSET ,
159
160
offsetof(ngx_http_modsecurity_loc_conf_t , enable ),
160
161
NULL },
162
+ { ngx_string ("ModSecurityXHeaders" ),
163
+ NGX_HTTP_MAIN_CONF |NGX_HTTP_SRV_CONF |NGX_HTTP_SIF_CONF |NGX_HTTP_LOC_CONF |NGX_HTTP_LIF_CONF |NGX_CONF_TAKE1 ,
164
+ ngx_conf_set_flag_slot ,
165
+ NGX_HTTP_LOC_CONF_OFFSET ,
166
+ offsetof(ngx_http_modsecurity_loc_conf_t , x_headers ),
167
+ NULL },
161
168
ngx_null_command
162
169
};
163
170
@@ -548,6 +555,10 @@ static int ngx_http_modsecurity_save_headers_in_visitor(void *data,
548
555
}
549
556
550
557
ngx_strlow (h -> lowcase_key , h -> key .data , h -> key .len );
558
+ h -> lowcase_key [h -> key .len ] = '\0' ;
559
+
560
+ if (!ngx_strcmp (h -> lowcase_key , "host" ))
561
+ return 1 ;
551
562
552
563
h -> hash = ngx_hash_key (h -> lowcase_key , h -> key .len );
553
564
@@ -822,6 +833,7 @@ ngx_http_modsecurity_save_headers_out_visitor(void *data,
822
833
ngx_http_upstream_main_conf_t * umcf ;
823
834
824
835
umcf = ngx_http_get_module_main_conf (r , ngx_http_upstream_module );
836
+ ngx_http_modsecurity_loc_conf_t * conf = ngx_http_get_module_loc_conf (r , ngx_http_modsecurity );
825
837
826
838
h = & he ;
827
839
@@ -838,6 +850,20 @@ ngx_http_modsecurity_save_headers_out_visitor(void *data,
838
850
839
851
ngx_strlow (h -> lowcase_key , h -> key .data , h -> key .len );
840
852
853
+ if (conf -> x_headers ) {
854
+ h -> lowcase_key [h -> key .len ] = '\0' ;
855
+ if (h -> lowcase_key [0 ] == 'x' &&
856
+ h -> lowcase_key [1 ] == '-' ) {
857
+
858
+ new_h = ngx_list_push (& r -> headers_out .headers );
859
+ new_h -> key = h -> key ;
860
+ new_h -> value = h -> value ;
861
+ new_h -> hash = 1 ;
862
+ return 1 ;
863
+
864
+ }
865
+ }
866
+
841
867
h -> hash = ngx_hash_key (h -> lowcase_key , h -> key .len );
842
868
843
869
hh = ngx_hash_find (& umcf -> headers_in_hash , h -> hash ,
@@ -1017,6 +1043,7 @@ ngx_http_modsecurity_create_loc_conf(ngx_conf_t *cf)
1017
1043
1018
1044
conf -> config = NGX_CONF_UNSET_PTR ;
1019
1045
conf -> enable = NGX_CONF_UNSET ;
1046
+ conf -> x_headers = NGX_CONF_UNSET ;
1020
1047
1021
1048
return conf ;
1022
1049
}
@@ -1030,6 +1057,7 @@ ngx_http_modsecurity_merge_loc_conf(ngx_conf_t *cf, void *parent,
1030
1057
ngx_http_modsecurity_loc_conf_t * conf = child ;
1031
1058
1032
1059
ngx_conf_merge_value (conf -> enable , prev -> enable , 0 );
1060
+ ngx_conf_merge_value (conf -> x_headers , prev -> x_headers , 0 );
1033
1061
ngx_conf_merge_ptr_value (conf -> config , prev -> config , NULL );
1034
1062
1035
1063
if (conf -> enable && conf -> config == NULL ) {
0 commit comments