Skip to content

Commit 19b8899

Browse files
author
Nitin Chaudhary
committed
Fix IPv6 private range validation
- Handle IPv6 bracket removal BEFORE port removal - Prevents incorrect truncation of IPv6 addresses - Fixes URLValidatorTest.BlocksIPv6PrivateRanges
1 parent be4d302 commit 19b8899

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

vnext/Shared/InputValidation.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,18 @@ std::string URLValidator::ExtractHostname(const std::string &url) {
9797

9898
std::string hostname = url.substr(hostStart, hostEnd - hostStart);
9999

100-
// Remove port if present
101-
size_t portPos = hostname.find(':');
102-
if (portPos != std::string::npos) {
103-
hostname = hostname.substr(0, portPos);
104-
}
105-
106-
// Remove IPv6 brackets
100+
// Handle IPv6 addresses first (they have brackets)
107101
if (!hostname.empty() && hostname[0] == '[') {
108102
size_t bracketEnd = hostname.find(']');
109103
if (bracketEnd != std::string::npos) {
110104
hostname = hostname.substr(1, bracketEnd - 1);
111105
}
106+
} else {
107+
// For non-IPv6, remove port if present (only after first colon)
108+
size_t portPos = hostname.find(':');
109+
if (portPos != std::string::npos) {
110+
hostname = hostname.substr(0, portPos);
111+
}
112112
}
113113

114114
std::transform(hostname.begin(), hostname.end(), hostname.begin(), [](unsigned char c) {

0 commit comments

Comments
 (0)