fix(towercore): block cross-subscriber bulk reads
- Proxy TowerCore frames and reject opcode 0x23 requests containing subscriber selectors. - Preserve checker bulk reads that address authenticated message IDs.
This commit is contained in:
1 parent
be18145fa6
commit
ea9f241058
4 files changed
+163
-2
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import importlib
|
||||
import importlib.util
|
||||
import unittest
|
||||
|
||||
|
||||
def frame(opcode: int, fields: list[tuple[int, bytes]]) -> bytes:
|
||||
payload = b"".join(
|
||||
tag.to_bytes(2, "little") + len(value).to_bytes(2, "little") + value
|
||||
for tag, value in fields
|
||||
)
|
||||
return b"LT" + bytes((1, opcode)) + b"\0" * 10 + len(payload).to_bytes(2, "little") + payload
|
||||
|
||||
|
||||
class GuardTests(unittest.TestCase):
|
||||
def test_blocks_cross_subscriber_bulk_read(self) -> None:
|
||||
guard = importlib.util.find_spec("guard")
|
||||
self.assertIsNotNone(guard, "Towercore guard is not implemented")
|
||||
module = importlib.import_module("guard")
|
||||
request = frame(0x23, [(0x0B, b"victim01"), (0x0B, b"victim02")])
|
||||
self.assertTrue(module.should_block(request))
|
||||
|
||||
def test_allows_checker_bulk_read_by_message_ids(self) -> None:
|
||||
guard = importlib.util.find_spec("guard")
|
||||
self.assertIsNotNone(guard, "Towercore guard is not implemented")
|
||||
module = importlib.import_module("guard")
|
||||
request = frame(0x23, [(0x0D, b"\x05\0\0\0"), (0x0D, b"\x06\0\0\0")])
|
||||
self.assertFalse(module.should_block(request))
|
||||
|
||||
def test_allows_other_commands_with_subscriber_field(self) -> None:
|
||||
guard = importlib.util.find_spec("guard")
|
||||
self.assertIsNotNone(guard, "Towercore guard is not implemented")
|
||||
module = importlib.import_module("guard")
|
||||
self.assertFalse(module.should_block(frame(0x07, [(0x0B, b"lookup01")])))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user