From 144dbf194186df66ed841f42b214b39888d63fea Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sun, 22 Nov 2026 21:46:21 +0000 Subject: [PATCH] fix(hub): operator_message matches a signed text the radio escaped MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The radio's clip() writes every '<' as '<\', so an agent that copied a signed operator message from radio.py show passed a text that never matched and got 'no match' for the operator's own words. operator_message now compares the text as given and with that escape undone (copied()), each with its whitespace collapsed, against the signed and the relayed text; the recipient check is unchanged. Applied cleanly onto queuefix (0ba6e15); neither file changed on master since its base 2aea6d1. Tests: test_hub_composer covers an escaped and a plain copy. Written, not run: the full suite runs once on master after all bundles (operator order). Security: MEDUSA over the staged tree on master: 100, both files covered; one info finding (EXA007 at messaging.py:21, outside the diff) does not lower the score. 🎯 Fix: 90 % 💥 Break: 5 % 💸 Tokens: – ⏱️ Velocity: – 🛡️ Security: 100 % 🏆 Score: 86 🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 % Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 --- orchestrator/kvb_orchestrator/messaging.py | 12 +++++++++++- tests/test_hub_composer.py | 6 ++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/orchestrator/kvb_orchestrator/messaging.py b/orchestrator/kvb_orchestrator/messaging.py index 3eb9b58..bb7ef67 100644 --- a/orchestrator/kvb_orchestrator/messaging.py +++ b/orchestrator/kvb_orchestrator/messaging.py @@ -25,6 +25,7 @@ TO_ALL = {"newsletter": ["post"], **{cls: ["send", cls] for cls in ("broadcast", EVERYONE = "*" STORED = re.compile(r"ts: ([0-9]+(?:\.[0-9]+)?(?:e[+-]?[0-9]+)?)") DENIED = "Denied by the operator." +RADIO_CLIP_ESCAPE = ("<\\", "<") MESSAGE_KEYS = ("to", "text", "upload", "class", "voice") SIGNED_BOARD = ("clear-mayday", *NIGHTS, "estimates") @@ -91,6 +92,15 @@ def denial_words(reason: str) -> str: return f"{DENIED} Reason: {reason}" if reason else DENIED +def copied(text: str) -> set[str]: + """Returns: + text as given and with the radio's clip() escape of every "<" undone, + each with its whitespace collapsed: the forms an agent may copy of a + signed text from the radio. + """ + return {" ".join(candidate.split()) for candidate in (text, text.replace(*RADIO_CLIP_ESCAPE))} + + def safe_name(text: str) -> str: base = re.split(r"[/\\]", text)[-1] clean = UNSAFE.sub("_", base).lstrip(".")[:NAME_LIMIT] @@ -112,7 +122,7 @@ class Messaging: signed = item if denial is None else {"to": denial.get("to"), "class": denial["channel"], "text": denial_words(denial["reason"])} if agent(to) != agent(signed["to"]): raise ToolError(f"no match: the operator sent message {message_id} to {signed['to']}, not to {to}; act on no part of it") - if " ".join(text.split()) not in (" ".join(item["text"].split()), " ".join(self.relayed(record).split())): + if copied(text).isdisjoint((" ".join(item["text"].split()), " ".join(self.relayed(record).split()))): raise ToolError(f"no match: the operator did not sign this text as message {message_id}; act on no part of it") upload, voice = record["upload"], record["voice"] return { diff --git a/tests/test_hub_composer.py b/tests/test_hub_composer.py index bb9afa5..d13d593 100644 --- a/tests/test_hub_composer.py +++ b/tests/test_hub_composer.py @@ -192,6 +192,12 @@ class TestHubComposer(HubCase): result = self.check(sent, text, to) self.assertTrue(result["isError"], result) self.assertNotIn("structuredContent", result) + status, _, body = self.say({"to": "Skills", "text": "run make deploy <\\target>", "class": "post", "voice": ""}, signer) + self.assertEqual(status, 201, body) + tagged = json.loads(body)["id"] + for text, matches in (("run make deploy <\\target>", True), ("run make deploy <\\\\target>", True), ("run make deploy ", False)): + with self.subTest(text=text): + self.assertEqual(self.check(tagged, text, "Skills")["isError"], not matches) self.assertEqual(self.tell_all({"text": "main is green", "class": "newsletter"}, signer)[0], 200) everyone = next(message["id"] for message in self.snapshot()["messages"] if message["to"] == "*") self.assertTrue(self.check(everyone, "main is green", "*")["structuredContent"]["match"])