Skip to content

Commit 93b65a3

Browse files
author
testgen-ci-bot
committed
Merge remote-tracking branch 'origin/enterprise' into feat/TG-1047-deduplicate-run-tables
2 parents 0a85164 + 5afa6a6 commit 93b65a3

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

testgen/mcp/server.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,20 @@ def _build_transport_security() -> TransportSecuritySettings:
9393
netloc = parsed.netloc
9494
scheme = parsed.scheme or "http"
9595

96+
# base_host (bare) is allowed alongside netloc: when BASE_URL carries a non-default
97+
# port, netloc and the :* wildcard only match a host that includes a port, but some
98+
# clients (e.g. hosted MCP gateways) send a port-less Host/Origin for their own host.
9699
allowed_hosts: set[str] = {
97100
netloc,
101+
base_host,
98102
f"{base_host}:*",
99103
"127.0.0.1:*",
100104
"localhost:*",
101105
"[::1]:*",
102106
}
103107
allowed_origins: set[str] = {
104108
f"{scheme}://{netloc}",
109+
f"{scheme}://{base_host}",
105110
"http://127.0.0.1:*", "https://127.0.0.1:*",
106111
"http://localhost:*", "https://localhost:*",
107112
"http://[::1]:*", "https://[::1]:*",

tests/unit/mcp/test_transport_security.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ def test_loopback_and_base_url_always_present():
3030
assert "https://localhost:*" in settings.allowed_origins
3131

3232

33+
def test_ported_base_url_also_allows_bare_host_and_origin():
34+
"""A BASE_URL with a non-default port also allows the bare (port-less) host and origin.
35+
36+
Clients such as hosted MCP gateways may send a port-less Host/Origin for the server's
37+
own host; the `:*` wildcard requires a port, so the bare forms must be present too.
38+
"""
39+
settings = _build_with("https://tg.example.com:8530")
40+
41+
assert "tg.example.com:8530" in settings.allowed_hosts
42+
assert "tg.example.com" in settings.allowed_hosts
43+
assert "https://tg.example.com:8530" in settings.allowed_origins
44+
assert "https://tg.example.com" in settings.allowed_origins
45+
46+
3347
def test_extra_host_without_port_gets_wildcard_and_bare():
3448
"""An extras entry without `:` is allowed both with a `:*` port wildcard and bare.
3549

0 commit comments

Comments
 (0)