fix(towercore): bind exported context to session

- Force EXPORT_CONTEXT to use session->UE after both peer selector paths.
- Strip tag 0x09 and 0x0b peer selectors in the protocol guard.
This commit is contained in:
TakuyaYagam1 committed 2026-11-29 15:41:12 +03:00
1 parent ce5eb09db3
commit aba00ab3ed
3 files changed
+23 -7

No files matched your search

+6 -3
View File
@@ -7,9 +7,12 @@ from pathlib import Path
path = Path("/towercore")
data = bytearray(path.read_bytes())
original = bytes.fromhex("84 00 c2 90")
replacement = bytes.fromhex("25 10 00 00")
for offset in (0x24604, 0x2487C):
patches = (
(0x23DC0, bytes.fromhex("d7 04 a0 10"), bytes.fromhex("10 00 65 de")),
(0x24604, bytes.fromhex("84 00 c2 90"), bytes.fromhex("25 10 00 00")),
(0x2487C, bytes.fromhex("84 00 c2 90"), bytes.fromhex("25 10 00 00")),
)
for offset, original, replacement in patches:
actual = bytes(data[offset : offset + len(original)])
if actual != original:
raise SystemExit(f"unexpected bytes at {offset:#x}: {actual.hex()}")
+8 -4
View File
@@ -5,8 +5,11 @@ import contextlib
import os
HEADER_SIZE = 16
TARGETED_READ_OPCODES = frozenset((0x21, 0x23))
SUBSCRIBER_TAG = 0x0B
FILTERED_SELECTOR_TAGS = {
0x21: frozenset((0x0B,)),
0x23: frozenset((0x0B,)),
0x40: frozenset((0x09, 0x0B)),
}
BACKEND_HOST = os.environ.get("BACKEND_HOST", "towercore")
BACKEND_PORT = int(os.environ.get("BACKEND_PORT", "7250"))
LISTEN_PORT = int(os.environ.get("LISTEN_PORT", "7250"))
@@ -18,7 +21,8 @@ def sanitize_frame(frame: bytes) -> bytes:
payload_size = int.from_bytes(frame[14:16], "little")
if len(frame) != HEADER_SIZE + payload_size:
raise ValueError("invalid frame length")
if frame[3] not in TARGETED_READ_OPCODES:
filtered_tags = FILTERED_SELECTOR_TAGS.get(frame[3])
if filtered_tags is None:
return frame
payload = frame[HEADER_SIZE:]
@@ -32,7 +36,7 @@ def sanitize_frame(frame: bytes) -> bytes:
end = offset + 4 + size
if end > len(payload):
raise ValueError("truncated TLV value")
if tag == SUBSCRIBER_TAG:
if tag in filtered_tags:
if sanitized is None:
sanitized = bytearray(payload[:offset])
elif sanitized is not None:
+9
View File
@@ -36,6 +36,15 @@ class GuardTests(unittest.TestCase):
)
self.assertEqual(module.sanitize_frame(request), frame(0x23, []))
def test_strips_peer_selector_from_export_context(self) -> None:
module = importlib.import_module("guard")
request = frame(
0x40,
[(0x09, b"peer-id"), (0x0B, b"victim01"), (0x0C, b"\x01\0\0\0")],
)
expected = frame(0x40, [(0x0C, b"\x01\0\0\0")])
self.assertEqual(module.sanitize_frame(request), expected)
def test_keeps_checker_read_by_message_ids(self) -> None:
guard = importlib.util.find_spec("guard")
self.assertIsNotNone(guard, "Towercore guard is not implemented")