The vulnerability, as described, is that the isPublic() function in the 'ip' package incorrectly classifies certain private IP addresses in non-standard formats (like '0x7F.1') as public.
The isPublic function's logic is simply !ip.isPrivate(addr). Therefore, the incorrect behavior of isPublic is a direct result of isPrivate failing to correctly identify these non-standard IP formats as private.
The patches (commits 32f468f1245574785ec080705737a579be1223aa and 6a3ada9b471b09d5f0f5be264911ab564bf67894) address this by overhauling ip.isPrivate. The changes include:
- Introducing a new function
ip.normalizeToLong(addr) to parse various IP notations (decimal, hex, octal, different numbers of parts) into a standard numerical representation.
- Modifying
ip.isPrivate to use this normalization for IPv4 addresses before performing checks.
- Enhancing
ip.isLoopback to correctly identify loopback addresses in these non-standard formats and calling this improved isLoopback at the beginning of ip.isPrivate.
Thus, ip.isPrivate is identified as a vulnerable function because it contained the defective IP address recognition logic. ip.isPublic is also identified as vulnerable because it directly exposed this flawed logic, leading to the reported security issue. Both functions process the potentially problematic IP address input.