diff --git a/tests/unit/python/utils/certs/test_tls_common.py b/tests/unit/python/utils/certs/test_tls_common.py index 10d84557ee..e51ef95881 100644 --- a/tests/unit/python/utils/certs/test_tls_common.py +++ b/tests/unit/python/utils/certs/test_tls_common.py @@ -133,6 +133,38 @@ class TestTlsCommon(unittest.TestCase): "x", domains=self.domains, forced_mode="invalid", err_prefix="t" ) + def test_resolve_term_clearnet_domain_swapped_to_onion_keeps_clearnet(self): + domains = {"svc-prx-openresty": ["abc.onion"]} + applications = { + "svc-prx-openresty": {"domains": {"canonical": ["infinito.test"]}} + } + app_id, primary = resolve_term( + "infinito.test", + domains=domains, + applications=applications, + forced_mode="auto", + err_prefix="t", + ) + self.assertEqual(app_id, "svc-prx-openresty") + self.assertEqual(primary, "infinito.test") + self.assertTrue(resolve_enabled({}, True, primary_domain=primary)) + + def test_resolve_term_alias_without_onion_swap_keeps_canonical(self): + domains = {"web-app-x": ["x.example"]} + applications = { + "web-app-x": { + "domains": {"canonical": ["x.example"], "aliases": ["old.example"]} + } + } + _, primary = resolve_term( + "old.example", + domains=domains, + applications=applications, + forced_mode="auto", + err_prefix="t", + ) + self.assertEqual(primary, "x.example") + def test_resolve_enabled_and_mode(self): app = {} self.assertTrue(resolve_enabled(app, True)) diff --git a/utils/tls_common.py b/utils/tls_common.py index 8cf2aaf3dc..ad8bfe425c 100644 --- a/utils/tls_common.py +++ b/utils/tls_common.py @@ -252,6 +252,14 @@ def resolve_term( primary = norm_domain( resolve_primary_domain_from_app(domains, str(app_id), err_prefix=err_prefix) ) + # Exception: an exclusive Tor app has its clearnet domain swapped for an + # onion one in the merged map, so a clearnet term would resolve to that + # onion primary and report TLS off. The webserver health check would + # then probe clearnet hosts over http (a 301 fails it), and the CSP + # crawler would scan servers/http and skip the https vhosts. Keep the + # requested clearnet domain, mirroring align_domain_to_consumer. + if is_onion_domain(primary) and not is_onion_domain(t): + return str(app_id), norm_domain(t) return str(app_id), primary app_id = t