From 8cb05198247530c9e4e79b01f9fa101582ade2d9 Mon Sep 17 00:00:00 2001 From: sec-check <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Tue, 27 Oct 2026 22:57:56 -0400 Subject: [PATCH] fix(relay): follow hub-registry relocation only to hub-fronted hosts The relay redials the registry's dashboardUrl with the contributor's token after a TLS altname mismatch. dashboardUrl is spoke-reported, so constrain the redial to https hosts under the hub's spoke domain. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: sec-check <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- bin/contributor-relay.js | 12 ++++++++++-- bin/contributor-relay.test.js | 6 ++++++ changelog.d/fixed-relay-relocation-host.md | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 changelog.d/fixed-relay-relocation-host.md diff --git a/bin/contributor-relay.js b/bin/contributor-relay.js index 5354057de4..1d049fe68f 100755 --- a/bin/contributor-relay.js +++ b/bin/contributor-relay.js @@ -1455,6 +1455,12 @@ function hubRegistryURLFor(hiveURL) { // (vanity hosts). Returns the registry's dashboardUrl as a wss:// contribute // URL, or null when the registry does not know the hive or lists the same // host we just failed on (so the retry would be identical). +// +// Only an https dashboardUrl under the hub's own spoke domain is followed. +// dashboardUrl is reported by each spoke in its heartbeat, so the registry can +// list any host; the relay dials the result with the contributor's token and +// runs whatever that host hands it, which must stay with hosts the hub fronts. +// Entries elsewhere are skipped, never redialed. function currentHiveURLFromRegistry(hiveURL, registry) { let u; try { u = new URL(String(hiveURL || '').trim()); } catch (_) { return null; } @@ -1465,10 +1471,12 @@ function currentHiveURLFromRegistry(hiveURL, registry) { if (!h || typeof h !== 'object' || typeof h.dashboardUrl !== 'string') continue; let d; try { d = new URL(h.dashboardUrl); } catch (_) { continue; } - const dHost = d.hostname.toLowerCase(); + const dHost = d.hostname.toLowerCase().replace(/\.$/, ''); if (h.id !== label && dHost.split('.')[0] !== label) continue; + if (d.protocol !== 'https:' || !dHost.endsWith('.' + DEFAULT_HUB_SPOKE_DOMAIN)) continue; if (dHost === host) return null; - d.protocol = d.protocol === 'http:' ? 'ws:' : 'wss:'; + d.hostname = dHost; + d.protocol = 'wss:'; d.pathname = '/contribute'; d.search = ''; d.hash = ''; diff --git a/bin/contributor-relay.test.js b/bin/contributor-relay.test.js index 9de87171dd..636378e823 100644 --- a/bin/contributor-relay.test.js +++ b/bin/contributor-relay.test.js @@ -15348,7 +15348,10 @@ test('tls-mismatch: hub registry lookup is only for hosted hives, and resolves b const registry = { hives: [ { id: 'hosted-available-oke-11-placeholder-r05x', dashboardUrl: 'https://hosted-kubestellar-hive-ojv6.hive.hivecommons.dev' }, + { id: 'hosted-other', dashboardUrl: 'https://hosted-plain.relay.example' }, { id: 'hosted-plain', dashboardUrl: 'https://hosted-plain.hive.hivecommons.dev' }, + { id: 'hosted-clear', dashboardUrl: 'http://hosted-clear.hive.hivecommons.dev' }, + { id: 'hosted-lookalike', dashboardUrl: 'https://hosted-lookalike.hive.hivecommons.dev.relay.example' }, { id: 'bad', dashboardUrl: 'not a url' }, null, 'junk', ] }; @@ -15357,6 +15360,9 @@ test('tls-mismatch: hub registry lookup is only for hosted hives, and resolves b { name: 'by vanity label', url: 'wss://hosted-kubestellar-hive-ojv6.old.example/contribute', want: 'wss://hosted-kubestellar-hive-ojv6.hive.hivecommons.dev/contribute' }, { name: 'same host already — no identical retry', url: 'wss://hosted-plain.hive.hivecommons.dev/contribute', want: null }, { name: 'unknown hive', url: 'wss://hosted-nope.hive.example/contribute', want: null }, + { name: 'entry outside the hub spoke domain is not followed', url: 'wss://hosted-other.hive.example/contribute', want: null }, + { name: 'plain-http entry is not followed', url: 'wss://hosted-clear.hive.example/contribute', want: null }, + { name: 'spoke-domain lookalike is not followed', url: 'wss://hosted-lookalike.hive.example/contribute', want: null }, { name: 'no registry', url: 'wss://hosted-plain.hive.example/contribute', registry: null, want: null }, { name: 'registry without hives array', url: 'wss://hosted-plain.hive.example/contribute', registry: { hives: 'x' }, want: null }, ]; diff --git a/changelog.d/fixed-relay-relocation-host.md b/changelog.d/fixed-relay-relocation-host.md new file mode 100644 index 0000000000..735be229c7 --- /dev/null +++ b/changelog.d/fixed-relay-relocation-host.md @@ -0,0 +1 @@ +- The contributor relay's one-shot hub-registry relocation (after a certificate hostname mismatch) now follows only an `https://` entry under the hub's own spoke domain; registry entries naming any other host, a plain-http URL, or a spoke-domain lookalike are skipped and the hub stays parked with the existing remediation line.