@@ -158,10 +158,10 @@ class JSChallenge(BaseJSChallenge):
158158 tempesta = {
159159 "config" : f"""
160160 server ${{server_ip}}:8000;
161-
161+
162162 listen 80;
163163 listen 443 proto=h2;
164-
164+
165165 tls_certificate ${{tempesta_workdir}}/tempesta.crt;
166166 tls_certificate_key ${{tempesta_workdir}}/tempesta.key;
167167 tls_match_any_server_name;
@@ -170,18 +170,32 @@ class JSChallenge(BaseJSChallenge):
170170 http_method_override_allowed true;
171171 http_strict_host_checking false;
172172 }}
173-
173+
174+ vhost tempesta-tech.com {{
175+ sticky {{
176+ cookie enforce name=cname max_misses={ MAX_MISSES } ;
177+ js_challenge resp_code=503 delay_min={ DELAY_MIN } delay_range={ DELAY_RANGE }
178+ ${{tempesta_workdir}}/js1.html;
179+ }}
180+ proxy_pass default;
181+ }}
182+
183+ vhost dev.tempesta-tech.com {{
184+ proxy_pass default;
185+ }}
186+
174187 block_action attack reply;
175188 block_action error reply;
176189
177190 cache 2;
178191 cache_methods GET HEAD POST;
179192 cache_fulfill * *;
180-
181- sticky {{
182- cookie enforce name=cname max_misses={ MAX_MISSES } ;
183- js_challenge resp_code=503 delay_min={ DELAY_MIN } delay_range={ DELAY_RANGE }
184- ${{tempesta_workdir}}/js1.html;
193+
194+ http_chain {{
195+ hdr accept == "text/html" -> jsch;
196+ hdr accept == "text/\*" -> jsch;
197+ host == "dev.tempesta-tech.com" -> dev.tempesta-tech.com;
198+ -> tempesta-tech.com;
185199 }}
186200 """
187201 }
@@ -217,7 +231,7 @@ def _test_first_request(self, client, request, method, accept, status, conn_is_c
217231 marks .Param (name = "GET_and_accept_html" , method = "GET" , accept = "text/html" , status = "503" ),
218232 marks .Param (name = "GET_and_accept_all" , method = "GET" , accept = "*/*" , status = "403" ),
219233 marks .Param (
220- name = "GET_and_accept_text_all" , method = "GET" , accept = "text/*" , status = "403 "
234+ name = "GET_and_accept_text_all" , method = "GET" , accept = "text/*" , status = "503 "
221235 ),
222236 marks .Param (name = "GET_and_accept_image" , method = "GET" , accept = "image/*" , status = "403" ),
223237 marks .Param (
@@ -229,9 +243,7 @@ def _test_first_request(self, client, request, method, accept, status, conn_is_c
229243 def test_first_request (self , name , method , accept , status ):
230244 """
231245 Not all requests are challengeable. Tempesta sends the challenge
232- only if the client can accept it, i.e. request should has GET method and
233- 'Accept: text/html'. In other cases normal browsers don't eval
234- JS code and TempestaFW is not trying to send the challenge to bots.
246+ only if the request matches http chain "jsch" rule.
235247 """
236248 self .start_all_services ()
237249
@@ -624,6 +636,24 @@ def test_method_override_with_cache(self, name, method, override, status):
624636 status ,
625637 )
626638
639+ def test_vhost_no_jsch_configured (self ):
640+ """
641+ Verify that vhost with non-configured "sticky" module doesn't send JS challenge
642+ even if it matches http_chain "jsch" rule.
643+ """
644+ self .start_all_services ()
645+
646+ client = self .get_client ("client-1" )
647+ request = client .create_request (
648+ method = "GET" , authority = "dev.tempesta-tech.com" , headers = [("accept" , "text/html" )]
649+ )
650+ client .send_request (request , "200" )
651+ resp = client .last_response
652+ self .assertIsNone (
653+ resp .headers .get ("Set-Cookie" , None ),
654+ "Tempesta added a Set-Cookie header, but js challange is not configured for vhost." ,
655+ )
656+
627657
628658@marks .parameterize_class (
629659 [
@@ -657,6 +687,9 @@ class JSChallengeCookieExpiresAndMethodOverride(BaseJSChallenge):
657687 tls_certificate ${{tempesta_workdir}}/tempesta.crt;
658688 tls_certificate_key ${{tempesta_workdir}}/tempesta.key;
659689 tls_match_any_server_name;
690+ frang_limits {{
691+ http_strict_host_checking false;
692+ }}
660693
661694 block_action attack reply;
662695 block_action error reply;
@@ -670,6 +703,15 @@ class JSChallengeCookieExpiresAndMethodOverride(BaseJSChallenge):
670703 ${{tempesta_workdir}}/js1.html;
671704 sess_lifetime 3;
672705 }}
706+
707+ vhost tempesta {{
708+ proxy_pass default;
709+ }}
710+
711+ http_chain {{
712+ hdr accept == "text/html" -> jsch;
713+ -> tempesta;
714+ }}
673715 """
674716 }
675717
0 commit comments