Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: fix IsIPAddress for IPv6 #53400

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/inspector_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ static bool IsIPAddress(const std::string& host) {
// Parse the IPv6 address to ensure it is syntactically valid.
char ipv6_str[INET6_ADDRSTRLEN];
std::copy(host.begin() + 1, host.end() - 1, ipv6_str);
ipv6_str[host.length()] = '\0';
ipv6_str[host.length() - 2] = '\0';
Copy link
Member

@anonrig anonrig Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better approach is to use Ada parser and validate if it is IPv6

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IsIPAddress function is invoked by the IsAllowedHost function, which accepts a host parameter. Typically, the host represents an IP address that may include a port number. For instance, in the test case found here, the host is solely an IP address.

Upon reviewing the Ada parser, it appears to be designed primarily for parsing URLs. So, I can't use it here like this: ada::parse(host).

Is there a potential method to adapt the Ada parser for use with IP addresses?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a bug fix, keeping the patch minimal is a good idea. Refactoring to use Ada or some entirely different validation instead does not need to happen in this PR.

unsigned char ipv6[sizeof(struct in6_addr)];
if (uv_inet_pton(AF_INET6, ipv6_str, ipv6) != 0) return false;

Expand Down
Loading