Commit b0a448a
committed
fix: properly handle IPv6 addresses in HTTP Host headers
This commit fixes IPv6 address handling in HTTP client Host headers
by adding bracket notation when required and improving URL parsing
validation.
Changes:
- Add automatic bracket wrapping for unbracketed IPv6 addresses in
Host headers for both standard and non-standard ports
- Add IPv6 bracketing for HTTPS default port (443) to ensure RFC
compliance even when port is omitted (e.g., Host: [::1])
- Fix off-by-one error in IPv6 bracket stripping (was removing one
extra character)
- Fix incorrect length calculation in flb_utils_copy_host_sds for
bracketed IPv6 extraction (changed from absolute position to
relative length to properly account for pos_init offset)
- Constrain IPv6 bracket validation to host portion only, preventing
false negatives when brackets appear in URL paths or query strings
- Use memchr with length limit for consistent and safe bracket
detection in both IPv6 and non-IPv6 cases
- Improve error handling in URL parsing with proper cleanup on failure
- Update TLS flag checking to use flb_stream_get_flag_status() for
more reliable detection
Tests:
- Add test for IPv6 with HTTPS on default port 443
- Add test cases for brackets in URL paths and query strings
- Add test cases for malformed bracket scenarios
Signed-off-by: Shelby Hagman <shelbyzh@amazon.com>1 parent 4f8c50b commit b0a448a
File tree
5 files changed
+346
-9
lines changed- src
- tests/internal
5 files changed
+346
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
36 | 41 | | |
| 42 | + | |
37 | 43 | | |
38 | 44 | | |
39 | 45 | | |
| |||
617 | 623 | | |
618 | 624 | | |
619 | 625 | | |
620 | | - | |
621 | | - | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
622 | 639 | | |
623 | 640 | | |
624 | | - | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
625 | 652 | | |
626 | 653 | | |
627 | 654 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1431 | 1431 | | |
1432 | 1432 | | |
1433 | 1433 | | |
1434 | | - | |
| 1434 | + | |
1435 | 1435 | | |
1436 | 1436 | | |
1437 | | - | |
| 1437 | + | |
1438 | 1438 | | |
1439 | 1439 | | |
1440 | 1440 | | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
1441 | 1476 | | |
1442 | 1477 | | |
1443 | 1478 | | |
| |||
1448 | 1483 | | |
1449 | 1484 | | |
1450 | 1485 | | |
| 1486 | + | |
1451 | 1487 | | |
1452 | 1488 | | |
1453 | 1489 | | |
| |||
1467 | 1503 | | |
1468 | 1504 | | |
1469 | 1505 | | |
1470 | | - | |
| 1506 | + | |
1471 | 1507 | | |
1472 | | - | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
1473 | 1517 | | |
1474 | 1518 | | |
1475 | 1519 | | |
| |||
1501 | 1545 | | |
1502 | 1546 | | |
1503 | 1547 | | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
1504 | 1552 | | |
1505 | 1553 | | |
1506 | 1554 | | |
1507 | 1555 | | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
1508 | 1560 | | |
1509 | 1561 | | |
1510 | 1562 | | |
| |||
1529 | 1581 | | |
1530 | 1582 | | |
1531 | 1583 | | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
1532 | 1593 | | |
1533 | 1594 | | |
1534 | 1595 | | |
| |||
1544 | 1605 | | |
1545 | 1606 | | |
1546 | 1607 | | |
| 1608 | + | |
1547 | 1609 | | |
1548 | 1610 | | |
1549 | 1611 | | |
| |||
1563 | 1625 | | |
1564 | 1626 | | |
1565 | 1627 | | |
1566 | | - | |
| 1628 | + | |
1567 | 1629 | | |
1568 | | - | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
1569 | 1639 | | |
1570 | 1640 | | |
1571 | 1641 | | |
| |||
1597 | 1667 | | |
1598 | 1668 | | |
1599 | 1669 | | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
1600 | 1674 | | |
1601 | 1675 | | |
1602 | 1676 | | |
1603 | 1677 | | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
1604 | 1682 | | |
1605 | 1683 | | |
1606 | 1684 | | |
| |||
0 commit comments