Commit 0425514
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)
- Strip IPv6 zone IDs (e.g., %eth0) from Host headers per RFC 3986
which prohibits zone IDs in URIs (e.g., fe80::1%eth0 becomes
[fe80::1]:8080 in Host header)
- Perform zone ID stripping before inet_pton() validation to ensure
proper IPv6 address detection for link-local addresses
- Add URI path prepending for URLs with query/fragment but no path
(e.g., http://example.com?query=1 becomes /?query=1) per RFC 7230
- Constrain IPv6 bracket validation to host portion only, preventing
false negatives when brackets appear in URL paths or query strings
- Update validate_ipv6_brackets() to recognize '?' and '#' as host
delimiters in addition to '/'
- Refactor URL parsing logic to eliminate duplication
- 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 IPv6 addresses with zone IDs (verifying zone ID
stripping behavior)
- Add test cases for brackets in URL paths and query strings
- Add test cases for malformed bracket scenarios
Signed-off-by: Shelby Hagman <[email protected]>1 parent 4f8c50b commit 0425514
File tree
5 files changed
+456
-31
lines changed- src
- tests/internal
5 files changed
+456
-31
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 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
622 | 665 | | |
623 | 666 | | |
624 | | - | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
625 | 675 | | |
626 | 676 | | |
627 | 677 | | |
| |||
| 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 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
| 1492 | + | |
| 1493 | + | |
| 1494 | + | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
| 1499 | + | |
| 1500 | + | |
| 1501 | + | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
1441 | 1531 | | |
1442 | 1532 | | |
1443 | 1533 | | |
| |||
1448 | 1538 | | |
1449 | 1539 | | |
1450 | 1540 | | |
| 1541 | + | |
1451 | 1542 | | |
1452 | 1543 | | |
1453 | 1544 | | |
| |||
1467 | 1558 | | |
1468 | 1559 | | |
1469 | 1560 | | |
1470 | | - | |
| 1561 | + | |
1471 | 1562 | | |
1472 | | - | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
1473 | 1572 | | |
1474 | 1573 | | |
1475 | 1574 | | |
| |||
1478 | 1577 | | |
1479 | 1578 | | |
1480 | 1579 | | |
| 1580 | + | |
1481 | 1581 | | |
1482 | 1582 | | |
1483 | 1583 | | |
1484 | 1584 | | |
1485 | 1585 | | |
1486 | 1586 | | |
1487 | 1587 | | |
| 1588 | + | |
1488 | 1589 | | |
1489 | | - | |
1490 | | - | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
1491 | 1595 | | |
1492 | | - | |
1493 | | - | |
| 1596 | + | |
1494 | 1597 | | |
1495 | 1598 | | |
1496 | | - | |
1497 | | - | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
1498 | 1604 | | |
1499 | 1605 | | |
1500 | 1606 | | |
1501 | | - | |
| 1607 | + | |
1502 | 1608 | | |
1503 | | - | |
1504 | | - | |
| 1609 | + | |
1505 | 1610 | | |
1506 | 1611 | | |
1507 | | - | |
1508 | | - | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
1509 | 1622 | | |
1510 | 1623 | | |
| 1624 | + | |
| 1625 | + | |
| 1626 | + | |
1511 | 1627 | | |
1512 | 1628 | | |
1513 | 1629 | | |
| |||
1529 | 1645 | | |
1530 | 1646 | | |
1531 | 1647 | | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
1532 | 1657 | | |
1533 | 1658 | | |
1534 | 1659 | | |
| |||
1544 | 1669 | | |
1545 | 1670 | | |
1546 | 1671 | | |
| 1672 | + | |
1547 | 1673 | | |
1548 | 1674 | | |
1549 | 1675 | | |
| |||
1563 | 1689 | | |
1564 | 1690 | | |
1565 | 1691 | | |
1566 | | - | |
| 1692 | + | |
1567 | 1693 | | |
1568 | | - | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
1569 | 1703 | | |
1570 | 1704 | | |
1571 | 1705 | | |
| |||
1574 | 1708 | | |
1575 | 1709 | | |
1576 | 1710 | | |
| 1711 | + | |
1577 | 1712 | | |
1578 | 1713 | | |
1579 | 1714 | | |
1580 | 1715 | | |
1581 | 1716 | | |
1582 | 1717 | | |
1583 | 1718 | | |
| 1719 | + | |
1584 | 1720 | | |
1585 | | - | |
1586 | | - | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
| 1724 | + | |
| 1725 | + | |
1587 | 1726 | | |
1588 | | - | |
1589 | | - | |
| 1727 | + | |
1590 | 1728 | | |
1591 | 1729 | | |
1592 | | - | |
1593 | | - | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
1594 | 1735 | | |
1595 | 1736 | | |
1596 | 1737 | | |
1597 | | - | |
| 1738 | + | |
1598 | 1739 | | |
1599 | | - | |
1600 | | - | |
| 1740 | + | |
1601 | 1741 | | |
1602 | 1742 | | |
1603 | | - | |
1604 | | - | |
| 1743 | + | |
1605 | 1744 | | |
1606 | 1745 | | |
1607 | 1746 | | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
1608 | 1759 | | |
1609 | 1760 | | |
1610 | 1761 | | |
| |||
0 commit comments