Skip to content

Fix: Validate CIDR range in isValidIPv4CidrNotation#102

Merged
dadepo merged 3 commits intomasterfrom
fix-ipv4-cidr-validation
Jun 8, 2025
Merged

Fix: Validate CIDR range in isValidIPv4CidrNotation#102
dadepo merged 3 commits intomasterfrom
fix-ipv4-cidr-validation

Conversation

@dadepo
Copy link
Member

@dadepo dadepo commented Jun 3, 2025

Closes #100

The isValidIPv4CidrNotation function was vulnerable to a crash
if the range part of the CIDR string (e.g., '192.168.1.0/range')
contained non-numeric characters like a period. This was because
the function attempted to convert this part directly to a Number
and BigInt without sufficient validation.

This commit introduces a regular expression check ( /^\d+$/ )
to ensure that the range string consists only of digits before
any conversion is attempted. This prevents the SyntaxError when
BigInt conversion fails due to invalid characters.

google-labs-jules bot and others added 3 commits June 3, 2025 15:54
This commit removes an explanatory comment that was added during
the previous fix for CIDR range validation. The comment, while
technically correct, was deemed out of scope for the specific
bug fix and could cause future confusion.

The removal of this comment does not affect the functionality
or the logic of the `isValidIPv4CidrNotation` function. All
tests continue to pass.
@dadepo dadepo merged commit 2daa583 into master Jun 8, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IPv4 Cidr validation (isValidIPv4CidrNotation) crashes if CIDR number (range) has a period (.) in it

1 participant