-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prevent successful requests from invalid host
- Loading branch information
Showing
2 changed files
with
35 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
04e3ece
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for addressing this vulnerability. I am now making the vulnerability report public in this comment.
The
req
library may send unintended requests when malformed URLs are provided0x01 Summary
The
req
library is a widely used HTTP library in Go. However, it does not handle malformed URLs effectively. As a result, after parsing a malformed URL, the library may send HTTP requests to unexpected destinations, potentially leading to security vulnerabilities or unintended behavior in applications relying on this library for handling HTTP requests.Despite developers potentially utilizing the
net/url
library to parse malformed URLs and implement blocklists to prevent HTTP requests to listed URLs, inconsistencies exist between how thenet/url
andreq
libraries parse URLs. These discrepancies can lead to the failure of defensive strategies, resulting in potential security threats such as Server-Side Request Forgery (SSRF) and Remote Code Execution (RCE).0x02 Details
2.1 Affected components
The vulnerable component is:
2.2 Attack scenario
A typical attack scenario is illustrated in the diagram below. The Validator checks whether the attacker-supplied URL is on the blocklist. If not, the URL is passed to the Requester for processing. The Requester is responsible for sending requests to the hostname specified by the URL.
This attack occurs when the Validator is the
url.Parse
function and the Requester is theclient.R().Get
function. An attacker can send a malformed URL to the Validator (e.g.,http://vulndⓔtector.com/
). After validation, the Validator finds that the URL is not on the blocklist (the hostname parsed by urlparse is empty). However, the Requester can still send requests to the domain with the hostnamevulndetector.com
.0x03 PoC
It is worth noting that the payload for this vulnerability and the range of versions affected may vary across different operating systems. The following is a collection of all payloads that may have a security impact.
Linux/macOS payloads:
You can verify this issue using the sample program below. Simply replace the payload variable in the verify function with the payload mentioned above to conduct the test.
Typical Example PoC
0x04 Impact
The impact of this vulnerability is huge because the
req
library is widely used. In many cases, developers need a blocklist to block on some keywords. However, the vulnerability will help attackers bypass the protections that developers have set up for schemes and hosts. The vulnerability will lead to SSRF[1] and RCE[2] vulnerabilities in several cases.This security issue has previously been identified, and a CVE number has been assigned. For more information, refer to [3] and [4].
Furthermore, it is worth noting that according to our tests, [urllib3](https://github.com/urllib3/urllib3) does not have this security vulnerability. Its implementation strictly follows the RFC3986 specification.
0x05 Mitigation
Special characters in user input can potentially lead to security vulnerabilities, so it is crucial to perform strict validation and sanitization before processing any requests. Carefully examine and handle these characters to mitigate risks and ensure the security of the system.
0x06 Reference
[1] https://cwe.mitre.org/data/definitions/918.html
[2] https://cwe.mitre.org/data/definitions/94.html
[3] https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-24329
[4] https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2024-22243
[5] https://datatracker.ietf.org/doc/html/rfc3986