private-ip is an npm package that serves to check if IP address is private.
Resources:
- Project's GitHub repository: https://github.com/frenchbread/private-ip
- Project's npm package: https://www.npmjs.com/package/private-ip
The private-ip package is vulnerable to an SSRF bypass where an attacker can provide an IP or hostname that resolves to a multicast IP address which is not included as part of the private IP ranges in the package's source code.
The relevant part of the source code is the following allowlist:
const PRIVATE_IP_RANGES = [
'0.0.0.0/8',
'10.0.0.0/8',
'100.64.0.0/10',
'127.0.0.0/8',
'169.254.0.0/16',
'172.16.0.0/12',
'192.0.0.0/24',
'192.0.0.0/29',
'192.0.0.8/32',
'192.0.0.9/32',
'192.0.0.10/32',
'192.0.0.170/32',
'192.0.0.171/32',
'192.0.2.0/24',
'192.31.196.0/24',
'192.52.193.0/24',
'192.88.99.0/24',
'192.168.0.0/16',
'192.175.48.0/24',
'198.18.0.0/15',
'198.51.100.0/24',
'203.0.113.0/24',
'240.0.0.0/4',
'255.255.255.255/32'
]This array is missing the multicast address space at 224.0.0.0/4
All versions of private-ip are vulnerable to this issue, up to and including to the latest version of 3.0.2.
- Install the
private-ippackage:
npm install private-ip- Define an
app.jsfile with the programmatic API ofprivate-ipas follows:
import is_ip_private from 'private-ip'
import ipaddr from 'ipaddr.js'
// -- private-ip
console.log(is_ip_private('127.0.0.1'))
console.log(is_ip_private('10.0.0.0'))
console.log(is_ip_private('169.254.0.1'))
console.log(is_ip_private('239.255.255.250'))
// -- ipaddr.js
console.log(ipaddr.parse('127.0.0.1').range())
console.log(ipaddr.parse('10.0.0.0').range())
console.log(ipaddr.parse('169.254.0.1').range())
console.log(ipaddr.parse('239.255.255.250').range())- Run the
app.jsfile:
node app.js- Observe that the
private-ippackage does not detect the multicast IP address239.255.255.250as a private IP address and returnstruefor all 4 checks.
As a case of comparison, the ipaddr.js package correctly identifies the multicast IP address as a non-private IP address.
import ipaddr from 'ipaddr.js'
// -- ipaddr.js
console.log(ipaddr.parse('127.0.0.1').range())
console.log(ipaddr.parse('10.0.0.0').range())
console.log(ipaddr.parse('169.254.0.1').range())
console.log(ipaddr.parse('239.255.255.250').range())// would result in the following stdout: // loopback // private // linkLocal // multicast
# Author
Liran Tal
GHSA-9h3q-32c7-r533