Skip to content

Instantly share code, notes, and snippets.

@d0rb
Created June 5, 2024 09:05
Show Gist options
  • Save d0rb/765b263c226edc3368e4ae90d440c05d to your computer and use it in GitHub Desktop.
Save d0rb/765b263c226edc3368e4ae90d440c05d to your computer and use it in GitHub Desktop.
CVE-2024-29415 represents a significant security vulnerability in the node-ip package, a popular Node.js library used to retrieve IPv4 addresses. This library, instrumental in many server-side applications, has been identified as containing a serious flaw in its IP address classification function, isPublic(). This flaw can lead to Server-Side Request Forgery (SSRF) attacks when private IP addresses are misclassified as public.
Vulnerability Description
The core issue lies in the isPublic() function, which incorrectly identifies certain IP address formats as public, even when they represent private or reserved addresses. Notable examples of such misclassifications include:
127.1
01200034567
012.1.2.3
000:0:0000::01
::fFFf:127.0.0.1
These addresses are either non-standard representations or improperly parsed, leading to potential security breaches if they are used in contexts where IP address validation is crucial for security.
Code Analysis
The vulnerability stems from insufficient validation and normalization in the isPublic() function. Here's the problematic part of the code:
javascript
ip.isPublic = function(ip) {
var parts = ip.split('.');
// Incorrect handling of non-standard formats and potential numeric parsing issues
return parts[0] != 10 && parts[0] != 192 && parts[0] != 172;
};
This simplistic check fails to consider non-standard and malformed IP addresses, leading to the misclassification described.
Example of Exploit
An attacker can exploit this vulnerability by manipulating inputs that are known to be misclassified by isPublic(). For example, consider a scenario where a web application uses this function to verify if an IP address is public before allowing HTTP requests to be sent to it. An attacker could use an input like 127.1 (which isPublic() mistakenly classifies as a public IP) to interact with local services on the server:
javascript
// Hypothetical usage in an application
if(ip.isPublic(userInput)) {
// The code intends only to allow public IPs
sendHttpRequest("http://" + userInput + "/api");
}
Using 127.1, an attacker can target internal services (like databases or admin interfaces) that listen on the local network, leading to data breaches or unauthorized actions.
Recommendations
To mitigate this vulnerability, developers using the node-ip package should:
Avoid using isPublic() for security-critical checks until a patch is fully applied and verified.
Implement additional validation checks that more thoroughly analyze IP address inputs.
Monitor and apply patches from the node-ip package maintainers as they become available.
Conclusion
The discovery of CVE-2024-29415 underscores the importance of robust input validation and the potential risks of relying on external libraries for security-sensitive operations. Developers must be vigilant and proactive in applying security patches and reviewing third-party code incorporated into their applications.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment