From 88739d160b7dec14876eff5e64b00a3bb26879d8 Mon Sep 17 00:00:00 2001 From: Audric Date: Wed, 27 May 2026 13:06:23 +0200 Subject: [PATCH] feat(trunk): apply per-link TG filter to monitoredTGs in peer roster The roster trim added in 7cf6589 dropped a peer node entirely when its *selected* TG was filtered, but a kept node (selected on a permitted TG) still carried its full monitoredTGs list verbatim in the status blob, so blacklisted / non-ALLOW_TGS TGs it was only monitoring leaked into /status.trunks[
].nodes[*].monitoredTGs and the MQTT/Redis mirrors. Filter each entry's monitoredTGs array in TrunkLink::handleMsgPeerNodeList with the same composite gate as the selected TG and the audio receive path (isBlacklisted(tg) || isBlacklisted(mapTgIn(tg)) || !isAllowed(tg)), so TG_MAP translation is honoured and the blacklist wins over an allow-prefix. Non-permitted and malformed (non-uint) entries are dropped; the array may become empty. Visibility-only: m_partner_nodes feeds statusJson() and onPeerNodeList() (MQTT/Redis), never routing. Adds test_21c_filter_trims_monitored_tgs_in_blob and documents the monitor-list trim in PEER_PROTOCOL.md. --- docs/PEER_PROTOCOL.md | 5 +++- src/svxlink/reflector/TrunkLink.cpp | 22 ++++++++++++++++ tests/test_trunk.py | 40 +++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/docs/PEER_PROTOCOL.md b/docs/PEER_PROTOCOL.md index 1987170..8eeb80b 100644 --- a/docs/PEER_PROTOCOL.md +++ b/docs/PEER_PROTOCOL.md @@ -554,7 +554,10 @@ entirely, so it never appears under `/status.trunks[
].nodes`, MQTT `nodes/`, or the Redis mirror — a filtered TG's roster is trimmed on this link just like its audio, even though the full snapshot is sent on the wire. (Satellite links filter on the *send* side via `SATELLITE_FILTER`; trunk -links have no roster filtering on send, so the trim happens on receive.) +links have no roster filtering on send, so the trim happens on receive.) The +same gate is then applied to each kept entry's `monitoredTGs` array inside the +status blob (see below), so a node retained because its *selected* TG is +permitted cannot surface filtered TGs it is only monitoring. The optional `status_blobs[i]` field carries the source reflector's `m_status["nodes"][callsign]` JSON serialised verbatim — the same rich diff --git a/src/svxlink/reflector/TrunkLink.cpp b/src/svxlink/reflector/TrunkLink.cpp index 6363736..d942b8d 100644 --- a/src/svxlink/reflector/TrunkLink.cpp +++ b/src/svxlink/reflector/TrunkLink.cpp @@ -2073,6 +2073,28 @@ void TrunkLink::handleMsgPeerNodeList(std::istream& is) } e.status = n.status; sanitizeJsonStrings(e.status); + + // Trim non-permitted TGs out of the status blob's monitoredTGs array + // with the same per-link gate as the selected TG above. Otherwise a + // node kept because its *selected* TG is permitted could still surface + // filtered TGs it is only monitoring into /status, MQTT and the Redis + // mirror. Values stay in the peer's wire numbering, matching e.tg. + if (e.status.isMember("monitoredTGs") && e.status["monitoredTGs"].isArray()) + { + Json::Value kept(Json::arrayValue); + for (const auto& mt : e.status["monitoredTGs"]) + { + if (!mt.isUInt()) continue; // drop malformed entries + const uint32_t tg = mt.asUInt(); + if (isBlacklisted(tg) || isBlacklisted(mapTgIn(tg)) || !isAllowed(tg)) + { + continue; + } + kept.append(tg); + } + e.status["monitoredTGs"] = kept; // may be empty + } + // Recipient-relative sat_id from the peer. Pass through as-is after // bounded sanitisation: empty = "on the peer itself", non-empty = // "on a satellite attached to the peer". diff --git a/tests/test_trunk.py b/tests/test_trunk.py index b86de16..ab9ce01 100644 --- a/tests/test_trunk.py +++ b/tests/test_trunk.py @@ -1711,6 +1711,46 @@ class TestTrunkIntegration(unittest.TestCase): finally: peer.close() + # ------------------------------------------------------------------ + # Test 21c: per-link TG filter trims monitoredTGs inside the status blob + # ------------------------------------------------------------------ + def test_21c_filter_trims_monitored_tgs_in_blob(self): + """A node kept because its SELECTED TG is permitted must still have + non-permitted entries trimmed from its status blob's monitoredTGs + array — the same per-link gate that drops whole entries (test_21b) + also scrubs the monitored list so filtered TGs never surface under + /status.trunks[X].nodes[*].monitoredTGs. + """ + peer = TrunkPeer() + peer.connect(*_trunk(self.PRIMARY)) + peer.handshake(trunk_id="TRUNK_TEST_FILTER", + local_prefix=FILTER_PREFIX, + secret=FILTER_SECRET) + try: + blocked_tg = int(T.TEST_PEER_FILTER["blacklist_tgs"]) # 12345 + # monitor list mixes allowed (7*), blacklisted, and disallowed TGs + blob = json.dumps({"monitoredTGs": [7100, blocked_tg, 99, 7205]}) + # selected TG 7100 is permitted, so the node itself is kept + peer.send_node_list([("N0RMON", 7100, 0.0, 0.0, "", blob, "")]) + + def monitored(): + status = get_status(*_http(self.PRIMARY)) + nodes = status["trunks"].get( + "TRUNK_TEST_FILTER", {}).get("nodes", []) + for n in nodes: + if n.get("callsign") == "N0RMON": + return n.get("monitoredTGs") + return None + + wait_until(lambda: monitored() is not None, + timeout=5.0, interval=0.25, + msg="Kept node N0RMON missing from trunk roster") + + self.assertEqual(sorted(monitored()), [7100, 7205], + f"monitoredTGs leaked filtered TGs: {monitored()}") + finally: + peer.close() + # ------------------------------------------------------------------ # Test 22: TG_MAP remaps incoming TGs # ------------------------------------------------------------------