Skip to content

Commit 9ca7d26

Browse files
authored
Merge pull request nginx-proxy#2537 from nginx-proxy/debug-endpoint-regexp
fix: do not render regexp hostname in debug endpoint response
2 parents a79445f + fdb7310 commit 9ca7d26

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

nginx.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,8 @@ upstream {{ $vpath.upstream }} {
380380
{{- end }}
381381

382382
{{- $debug_vhost := deepCopy .VHost }}
383-
{{- $_ := set $debug_vhost "hostname" .Hostname }}
383+
{{- /* If it's a regexp, do not render the Hostname to the response to avoid rendering config breaking characters */}}
384+
{{- $_ := set $debug_vhost "hostname" (.VHost.is_regexp | ternary "Hostname is a regexp and unsafe to include in the debug response." .Hostname) }}
384385
{{- $_ := set $debug_vhost "paths" $debug_paths }}
385386

386387
{{- $debug_response := dict

test/test_debug_endpoint/test_global.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_debug_endpoint_response_contains_expected_values(docker_compose, nginxp
1919
assert jsonResponse["vhost"]["enable_debug_endpoint"] == True
2020

2121

22-
def test_debug_endpoint_pahts_stripped_if_response_too_long(docker_compose, nginxproxy):
22+
def test_debug_endpoint_paths_stripped_if_response_too_long(docker_compose, nginxproxy):
2323
r = nginxproxy.get("http://stripped.debug.nginx-proxy.example/nginx-proxy-debug")
2424
assert r.status_code == 200
2525
try:
@@ -31,6 +31,16 @@ def test_debug_endpoint_pahts_stripped_if_response_too_long(docker_compose, ngin
3131
assert jsonResponse["warning"] == "Virtual paths configuration for this hostname is too large and has been stripped from response."
3232

3333

34+
def test_debug_endpoint_hostname_replaced_by_warning_if_regexp(docker_compose, nginxproxy):
35+
r = nginxproxy.get("http://regexp.foo.debug.nginx-proxy.example/nginx-proxy-debug")
36+
assert r.status_code == 200
37+
try:
38+
jsonResponse = json.loads(r.text)
39+
except ValueError as err:
40+
pytest.fail("Failed to parse debug endpoint response as JSON: %s" % err, pytrace=False)
41+
assert jsonResponse["vhost"]["hostname"] == "Hostname is a regexp and unsafe to include in the debug response."
42+
43+
3444
def test_debug_endpoint_is_disabled_per_container(docker_compose, nginxproxy):
3545
r = nginxproxy.get("http://disabled.debug.nginx-proxy.example/nginx-proxy-debug")
3646
assert r.status_code == 404

test/test_debug_endpoint/test_global.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ services:
4242
"/18":
4343
"/19":
4444
"/20":
45+
46+
debug_regexp:
47+
image: web
48+
expose:
49+
- "84"
50+
environment:
51+
WEB_PORTS: 84
52+
VIRTUAL_HOST: ~^regexp.*\.debug.nginx-proxy.example
4553

4654
debug_disabled:
4755
image: web

0 commit comments

Comments
 (0)