summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2026-11-28 21:05:13 +0100
committerDirk Engling <erdgeist@erdgeist.org>2026-11-28 21:05:13 +0100
commit70485a0ecf6b1ae9520deb4af0490fdb48643836 (patch)
tree53585c4881a8e55fc993d06482b1e328481bad2b /tests
parent1853a6c5bdc8acb0ebef904e7c6cbf101cbe7eea (diff)
Prevent amplification attacks, only send id mis-match errors for sensible packets lengths
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/test_udp.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/integration/test_udp.py b/tests/integration/test_udp.py
index 3afe4ef..b60bd56 100644
--- a/tests/integration/test_udp.py
+++ b/tests/integration/test_udp.py
@@ -44,6 +44,17 @@ class UdpProtocol(TrackerTestCase):
44 self.assertEqual(action, 3, "action 3 is the error packet") 44 self.assertEqual(action, 3, "action 3 is the error packet")
45 self.assertIn(b"Connection ID missmatch", answer[8:]) 45 self.assertIn(b"Connection ID missmatch", answer[8:])
46 46
47 def test_a_wrong_connection_id_is_not_answered_with_more_than_was_sent(self):
48 """The sender's address is unverified at this point, so the error
49 must not be a way to throw bytes at somebody else."""
50 scrape = struct.pack(">QII", 0, 2, 3) + self.hash_for("udpbadscrape")
51 answer = self.tracker.udp_raw(scrape)
52 self.assertIsNotNone(answer, "a whole scrape is long enough to be told")
53 self.assertLessEqual(len(answer), len(scrape))
54 self.assertIsNone(self.tracker.udp_raw(scrape[:16]))
55 self.assertIsNone(self.tracker.udp_raw(scrape[: len(answer) - 1]))
56 self.assertIsNotNone(self.tracker.udp_raw(scrape[: len(answer)]))
57
47 def test_a_packet_shorter_than_the_header_is_ignored(self): 58 def test_a_packet_shorter_than_the_header_is_ignored(self):
48 self.assertIsNone(self.tracker.udp_raw(b"\x00" * 15)) 59 self.assertIsNone(self.tracker.udp_raw(b"\x00" * 15))
49 60