X Tutup
Skip to content

Fix IPv6 address validation to reject invalid formats#114245

Closed
mxtherfxcker wants to merge 1 commit intogodotengine:masterfrom
mxtherfxcker:fix/ipv6-validation
Closed

Fix IPv6 address validation to reject invalid formats#114245
mxtherfxcker wants to merge 1 commit intogodotengine:masterfrom
mxtherfxcker:fix/ipv6-validation

Conversation

@mxtherfxcker
Copy link
Contributor

Description

Fix IPv6 address validation to reject invalid formats

Problem

The String::is_valid_ip_address() method had incorrect validation logic that accepted invalid IPv6 and IPv4 addresses

Related Issues

Fixes #112511
Similar to #112554

@mxtherfxcker mxtherfxcker requested a review from a team as a code owner December 20, 2025 17:10
@Calinou Calinou added this to the 4.6 milestone Dec 21, 2025
@fire fire requested a review from a team December 22, 2025 20:03
bool String::is_valid_ip_address() const {
if (find_char(':') >= 0) {
Vector<String> ip = split(":");
int double_colons = 0, consecutive = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
int double_colons = 0, consecutive = 0;
int double_colons = 0;
int consecutive = 0;

Please put declarations on individual lines for readability

if (n.is_valid_hex_number(false)) {
int64_t nint = n.hex_to_int();
if (nint < 0 || nint > 0xffff) {
if (n.find_char('.') >= 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (n.find_char('.') >= 0) {
if (n.contains_char('.')) {

Copy link
Collaborator

@Faless Faless left a comment

Choose a reason for hiding this comment

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

I don't fully understand the logic inside the change.

The parsing seems to be looking for . (dots) while decoding an IPv6, but those should not be allowed AFAIK, am I missing something?

@Faless
Copy link
Collaborator

Faless commented Jan 9, 2026

The parsing seems to be looking for . (dots) while decoding an IPv6, but those should not be allowed AFAIK, am I missing something?

Ah, it seems that's to support the IPv4-mapped IPv6 address format: ::FFFF:192.0.2.1.

@mxtherfxcker
Copy link
Contributor Author

The parsing seems to be looking for . (dots) while decoding an IPv6, but those should not be allowed AFAIK, am I missing something?

Ah, it seems that's to support the IPv4-mapped IPv6 address format: ::FFFF:192.0.2.1.

Yeah, this is it.

@akien-mga
Copy link
Member

akien-mga commented Jan 13, 2026

Superseded by #114827. Thanks for the contribution!

@akien-mga akien-mga closed this Jan 13, 2026
@akien-mga akien-mga removed this from the 4.6 milestone Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IPv6 address validation accepts invalid addresses

5 participants

X Tutup