ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
feat(sites): warn when the site base domain overlaps the panel domain
Juan Deniscfe8317ea323
diff --git a/backend/app/notifications/catalog.py b/backend/app/notifications/catalog.pyindex 9bbcdc15..f9fc7b9b 100644--- a/backend/app/notifications/catalog.py+++ b/backend/app/notifications/catalog.py@@ -87,6 +87,12 @@ _CATALOG = {'severity': 'warning','category': 'system',},+ 'sites.publish.base_overlaps_panel': {+ 'title': 'Site base domain overlaps the panel domain',+ 'template': 'generic',+ 'severity': 'warning',+ 'category': 'system',+ },# Multi-alert monitoring digest (used by the legacy send_all path).'monitoring.alert': {'title': 'ServerKit alert',diff --git a/backend/app/services/site_domain_service.py b/backend/app/services/site_domain_service.pyindex e384f7b8..f1ed6b5f 100644--- a/backend/app/services/site_domain_service.py+++ b/backend/app/services/site_domain_service.py@@ -141,14 +141,21 @@ class SiteDomainService:@classmethoddef panel_host(cls):- """Hostname the ServerKit panel itself is served on (from the canonical- domain / panel origin), or ``None``. Used to tailor DNS guidance — an- install on a subdomain (``panel.example.com``) needs a different base- domain than one on the apex (``example.com``)."""- origin = cls.panel_origin()- if not origin:+ """Hostname the ServerKit panel *itself* is served on, from an explicitly+ configured panel domain (``canonical_domain`` setting, else the+ ``PUBLIC_URL`` / ``SERVERKIT_PUBLIC_URL`` env), or ``None``.++ Deliberately does NOT use ``panel_origin``'s base-domain fallback — that+ would make the panel host equal the sites base domain and defeat both the+ subdomain-vs-apex suggestion and the base/panel overlap check.+ """+ domain = SystemSettings.get('canonical_domain')+ if not domain:+ domain = (current_app.config.get('PUBLIC_URL')+ or current_app.config.get('SERVERKIT_PUBLIC_URL'))+ if not domain:return None- host = origin.split('://', 1)[-1].split('/', 1)[0].split(':', 1)[0]+ host = str(domain).split('://', 1)[-1].split('/', 1)[0].split(':', 1)[0]return host.strip().lower().strip('.') or None@classmethod@@ -173,6 +180,43 @@ class SiteDomainService:parent = '.'.join(parts[1:]) if len(parts) >= 3 else hostreturn f'apps.{parent}'+ @classmethod+ def base_domain_overlaps_panel(cls):+ """When the managed-sites wildcard (``*.<base>``) would also capture the+ panel's own hostname, return a human explanation; else ``None``.++ Two overlaps matter:++ * **panel host == base** — the wildcard setup's apex ``<base>`` A record+ repoints the panel's own domain at the site server, and every+ ``*.<base>`` becomes a managed site.+ * **panel host is a direct (single-label) child of base**+ (``panel.example.com`` under ``example.com``) — ``*.<base>`` matches the+ panel host, so it keeps working only while its explicit ``<panel>``+ record out-specifies the wildcard; drop that record and the panel+ silently falls into the site-serving nginx.++ A *deeper* descendant (``a.b.<base>``) is safe — a wildcard is single-label.+ """+ base = cls.base_domain()+ panel = cls.panel_host()+ if not base or not panel or panel == 'localhost' or panel.replace('.', '').isdigit():+ return None+ if panel == base:+ return (f'The panel is served at {panel} — the same domain set as the '+ f'managed-sites base. Every *.{base} then becomes a site and the '+ f'{base} record is managed for you. Use a dedicated base such as '+ f'apps.{base} to keep the panel separate.')+ if panel.endswith('.' + base):+ label = panel[: -(len(base) + 1)]+ if '.' not in label: # direct child only — *.<base> is single-label+ return (f'The panel host {panel} sits directly under the managed-sites '+ f'base {base}, so the *.{base} wildcard also matches it. The '+ f'panel keeps working only while its own {panel} DNS record '+ f'out-specifies the wildcard — pick a base that does not '+ f'contain the panel host (e.g. apps.{base}) to avoid this.')+ return None+@classmethoddef publishing_gaps(cls):"""The managed-sites publishing config gaps that are open *right now*, as@@ -196,6 +240,13 @@ class SiteDomainService:}]gaps = []+ overlap = cls.base_domain_overlaps_panel()+ if overlap:+ gaps.append({+ 'code': 'base_overlaps_panel',+ 'event': 'sites.publish.base_overlaps_panel',+ 'message': overlap,+ })if not cls.https_enabled():gaps.append({'code': 'http_only',diff --git a/backend/tests/test_sites_publishing_gaps.py b/backend/tests/test_sites_publishing_gaps.pyindex 8c6a5728..9922fdb0 100644--- a/backend/tests/test_sites_publishing_gaps.py+++ b/backend/tests/test_sites_publishing_gaps.py@@ -90,6 +90,39 @@ def test_no_base_domain_message_includes_suggestion(app, monkeypatch):assert 'apps.example.com' in msg+# ── base-domain / panel-domain overlap (the wildcard footgun) ────────────────++def test_overlap_when_base_equals_panel(app, monkeypatch):+ from app.services.site_domain_service import SiteDomainService+ _set('sites_base_domain', 'example.com')+ _set('canonical_domain', 'example.com') # panel IS the base+ assert SiteDomainService.base_domain_overlaps_panel() is not None+ assert 'base_overlaps_panel' in [g['code'] for g in SiteDomainService.publishing_gaps()]+++def test_overlap_when_panel_is_direct_child_of_base(app, monkeypatch):+ from app.services.site_domain_service import SiteDomainService+ _set('sites_base_domain', 'example.com')+ _set('canonical_domain', 'panel.example.com') # *.example.com matches panel+ msg = SiteDomainService.base_domain_overlaps_panel()+ assert msg and 'panel.example.com' in msg+++def test_no_overlap_for_deep_descendant(app, monkeypatch):+ from app.services.site_domain_service import SiteDomainService+ _set('sites_base_domain', 'example.com')+ _set('canonical_domain', 'a.b.example.com') # wildcard is single-label+ assert SiteDomainService.base_domain_overlaps_panel() is None+++def test_no_overlap_when_base_is_scoped_label(app, monkeypatch):+ from app.services.site_domain_service import SiteDomainService+ _set('sites_base_domain', 'apps.example.com') # the recommended shape+ _set('canonical_domain', 'panel.example.com')+ assert SiteDomainService.base_domain_overlaps_panel() is None+ assert 'base_overlaps_panel' not in [g['code'] for g in SiteDomainService.publishing_gaps()]++# ── notify_publishing_gaps (in-app, deduped) ─────────────────────────────────def test_notify_sends_once_then_dedupes(app, monkeypatch):