@@ -954,6 +954,15 @@ impl UdpSocket {
954
954
/// When there is no pending data, `Err(io::ErrorKind::WouldBlock)` is
955
955
/// returned. This function is usually paired with `readable()`.
956
956
///
957
+ /// # Notes
958
+ /// Note that the socket address **cannot** be implicitly trusted, because it is relatively
959
+ /// trivial to send a UDP datagram with a spoofed origin in a [packet injection attack].
960
+ /// Because UDP is stateless and does not validate the origin of a packet,
961
+ /// the attacker does not need to be able to intercept traffic in order to interfere.
962
+ /// It is important to be aware of this when designing your application-level protocol.
963
+ ///
964
+ /// [packet injection attack]: https://en.wikipedia.org/wiki/Packet_injection
965
+ ///
957
966
/// # Examples
958
967
///
959
968
/// ```no_run
@@ -1177,6 +1186,15 @@ impl UdpSocket {
1177
1186
/// Ok(())
1178
1187
/// }
1179
1188
/// ```
1189
+ ///
1190
+ /// # Notes
1191
+ /// Note that the socket address **cannot** be implicitly trusted, because it is relatively
1192
+ /// trivial to send a UDP datagram with a spoofed origin in a [packet injection attack].
1193
+ /// Because UDP is stateless and does not validate the origin of a packet,
1194
+ /// the attacker does not need to be able to intercept traffic in order to interfere.
1195
+ /// It is important to be aware of this when designing your application-level protocol.
1196
+ ///
1197
+ /// [packet injection attack]: https://en.wikipedia.org/wiki/Packet_injection
1180
1198
pub async fn recv_from ( & self , buf : & mut [ u8 ] ) -> io:: Result < ( usize , SocketAddr ) > {
1181
1199
self . io
1182
1200
. registration ( )
@@ -1201,6 +1219,15 @@ impl UdpSocket {
1201
1219
/// # Errors
1202
1220
///
1203
1221
/// This function may encounter any standard I/O error except `WouldBlock`.
1222
+ ///
1223
+ /// # Notes
1224
+ /// Note that the socket address **cannot** be implicitly trusted, because it is relatively
1225
+ /// trivial to send a UDP datagram with a spoofed origin in a [packet injection attack].
1226
+ /// Because UDP is stateless and does not validate the origin of a packet,
1227
+ /// the attacker does not need to be able to intercept traffic in order to interfere.
1228
+ /// It is important to be aware of this when designing your application-level protocol.
1229
+ ///
1230
+ /// [packet injection attack]: https://en.wikipedia.org/wiki/Packet_injection
1204
1231
pub fn poll_recv_from (
1205
1232
& self ,
1206
1233
cx : & mut Context < ' _ > ,
@@ -1233,6 +1260,16 @@ impl UdpSocket {
1233
1260
/// When there is no pending data, `Err(io::ErrorKind::WouldBlock)` is
1234
1261
/// returned. This function is usually paired with `readable()`.
1235
1262
///
1263
+ /// # Notes
1264
+ ///
1265
+ /// Note that the socket address **cannot** be implicitly trusted, because it is relatively
1266
+ /// trivial to send a UDP datagram with a spoofed origin in a [packet injection attack].
1267
+ /// Because UDP is stateless and does not validate the origin of a packet,
1268
+ /// the attacker does not need to be able to intercept traffic in order to interfere.
1269
+ /// It is important to be aware of this when designing your application-level protocol.
1270
+ ///
1271
+ /// [packet injection attack]: https://en.wikipedia.org/wiki/Packet_injection
1272
+ ///
1236
1273
/// # Examples
1237
1274
///
1238
1275
/// ```no_run
@@ -1336,6 +1373,12 @@ impl UdpSocket {
1336
1373
/// If you're merely interested in learning the sender of the data at the head of the queue,
1337
1374
/// try [`peek_sender`].
1338
1375
///
1376
+ /// Note that the socket address **cannot** be implicitly trusted, because it is relatively
1377
+ /// trivial to send a UDP datagram with a spoofed origin in a [packet injection attack].
1378
+ /// Because UDP is stateless and does not validate the origin of a packet,
1379
+ /// the attacker does not need to be able to intercept traffic in order to interfere.
1380
+ /// It is important to be aware of this when designing your application-level protocol.
1381
+ ///
1339
1382
/// # Examples
1340
1383
///
1341
1384
/// ```no_run
@@ -1356,6 +1399,7 @@ impl UdpSocket {
1356
1399
/// ```
1357
1400
///
1358
1401
/// [`peek_sender`]: method@Self::peek_sender
1402
+ /// [packet injection attack]: https://en.wikipedia.org/wiki/Packet_injection
1359
1403
pub async fn peek_from ( & self , buf : & mut [ u8 ] ) -> io:: Result < ( usize , SocketAddr ) > {
1360
1404
self . io
1361
1405
. registration ( )
@@ -1383,6 +1427,12 @@ impl UdpSocket {
1383
1427
/// If you're merely interested in learning the sender of the data at the head of the queue,
1384
1428
/// try [`poll_peek_sender`].
1385
1429
///
1430
+ /// Note that the socket address **cannot** be implicitly trusted, because it is relatively
1431
+ /// trivial to send a UDP datagram with a spoofed origin in a [packet injection attack].
1432
+ /// Because UDP is stateless and does not validate the origin of a packet,
1433
+ /// the attacker does not need to be able to intercept traffic in order to interfere.
1434
+ /// It is important to be aware of this when designing your application-level protocol.
1435
+ ///
1386
1436
/// # Return value
1387
1437
///
1388
1438
/// The function returns:
@@ -1396,6 +1446,7 @@ impl UdpSocket {
1396
1446
/// This function may encounter any standard I/O error except `WouldBlock`.
1397
1447
///
1398
1448
/// [`poll_peek_sender`]: method@Self::poll_peek_sender
1449
+ /// [packet injection attack]: https://en.wikipedia.org/wiki/Packet_injection
1399
1450
pub fn poll_peek_from (
1400
1451
& self ,
1401
1452
cx : & mut Context < ' _ > ,
@@ -1442,7 +1493,14 @@ impl UdpSocket {
1442
1493
/// If you're merely interested in learning the sender of the data at the head of the queue,
1443
1494
/// try [`try_peek_sender`].
1444
1495
///
1496
+ /// Note that the socket address **cannot** be implicitly trusted, because it is relatively
1497
+ /// trivial to send a UDP datagram with a spoofed origin in a [packet injection attack].
1498
+ /// Because UDP is stateless and does not validate the origin of a packet,
1499
+ /// the attacker does not need to be able to intercept traffic in order to interfere.
1500
+ /// It is important to be aware of this when designing your application-level protocol.
1501
+ ///
1445
1502
/// [`try_peek_sender`]: method@Self::try_peek_sender
1503
+ /// [packet injection attack]: https://en.wikipedia.org/wiki/Packet_injection
1446
1504
pub fn try_peek_from ( & self , buf : & mut [ u8 ] ) -> io:: Result < ( usize , SocketAddr ) > {
1447
1505
self . io
1448
1506
. registration ( )
@@ -1454,7 +1512,14 @@ impl UdpSocket {
1454
1512
/// This is equivalent to calling [`peek_from`] with a zero-sized buffer,
1455
1513
/// but suppresses the `WSAEMSGSIZE` error on Windows and the "invalid argument" error on macOS.
1456
1514
///
1515
+ /// Note that the socket address **cannot** be implicitly trusted, because it is relatively
1516
+ /// trivial to send a UDP datagram with a spoofed origin in a [packet injection attack].
1517
+ /// Because UDP is stateless and does not validate the origin of a packet,
1518
+ /// the attacker does not need to be able to intercept traffic in order to interfere.
1519
+ /// It is important to be aware of this when designing your application-level protocol.
1520
+ ///
1457
1521
/// [`peek_from`]: method@Self::peek_from
1522
+ /// [packet injection attack]: https://en.wikipedia.org/wiki/Packet_injection
1458
1523
pub async fn peek_sender ( & self ) -> io:: Result < SocketAddr > {
1459
1524
self . io
1460
1525
. registration ( )
@@ -1474,7 +1539,14 @@ impl UdpSocket {
1474
1539
/// `Waker` from the `Context` passed to the most recent call will be scheduled to
1475
1540
/// receive a wakeup.
1476
1541
///
1542
+ /// Note that the socket address **cannot** be implicitly trusted, because it is relatively
1543
+ /// trivial to send a UDP datagram with a spoofed origin in a [packet injection attack].
1544
+ /// Because UDP is stateless and does not validate the origin of a packet,
1545
+ /// the attacker does not need to be able to intercept traffic in order to interfere.
1546
+ /// It is important to be aware of this when designing your application-level protocol.
1547
+ ///
1477
1548
/// [`poll_peek_from`]: method@Self::poll_peek_from
1549
+ /// [packet injection attack]: https://en.wikipedia.org/wiki/Packet_injection
1478
1550
pub fn poll_peek_sender ( & self , cx : & mut Context < ' _ > ) -> Poll < io:: Result < SocketAddr > > {
1479
1551
self . io
1480
1552
. registration ( )
@@ -1485,6 +1557,14 @@ impl UdpSocket {
1485
1557
///
1486
1558
/// When there is no pending data, `Err(io::ErrorKind::WouldBlock)` is
1487
1559
/// returned. This function is usually paired with `readable()`.
1560
+ ///
1561
+ /// Note that the socket address **cannot** be implicitly trusted, because it is relatively
1562
+ /// trivial to send a UDP datagram with a spoofed origin in a [packet injection attack].
1563
+ /// Because UDP is stateless and does not validate the origin of a packet,
1564
+ /// the attacker does not need to be able to intercept traffic in order to interfere.
1565
+ /// It is important to be aware of this when designing your application-level protocol.
1566
+ ///
1567
+ /// [packet injection attack]: https://en.wikipedia.org/wiki/Packet_injection
1488
1568
pub fn try_peek_sender ( & self ) -> io:: Result < SocketAddr > {
1489
1569
self . io
1490
1570
. registration ( )
0 commit comments