SSRF via potential filter bypass with too lax local domain checking
Nextcloud's local-address filter did not block Google Cloud and Alibaba Cloud metadata endpoints, leaving it vulnerable to SSRF on those hosts.
Originally disclosed on HackerOne
- Triaged in 11 hours
- Fixed in 2 months
- Paid in 3 months
- Disclosed after 3 months
Summary by the program
Security advisory at https://github.com/nextcloud/security-advisories/security/advisories/GHSA-rmf9-w497-8cq8
The report
Summary:
Hi.
Reviewing the code for filtering for ssrf, in preventLocalAddress, we can see that it calls the function ThrowIfLocalAddress(). It has three common checks, first, it checks if the string is localhost, or if it ends in .local or .localhost
// Disallow localhost and local network
if ($host === 'localhost' || substr($host, -6) === '.local' || substr($host, -10) === '.localhost') {
$this->logger->warning("Host $host was not connected to because it violates local access rules");
throw new LocalServerException('Host violates local access rules');
}
Second check, it checks if the provided url is only a host
// Disallow hostname only
if (substr_count($host, '.') === 0 && !(bool)filter_var($host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$this->logger->warning("Host $host was not connected to because it violates local access rules");
throw new LocalServerException('Host violates local access rules');
}
Lastly, it checks if the user input is an ip, if it is, it checks if it is not in the FILTER_FLAG_NO_PRIV_RANGE, or FILTER_FLAG_NO_RES_RANGE.
These checks lack something tho. Checks for metadata. Specifically the Alibaba metadata, and google cloud metadata.
Other metadata like aws and digital ocean uses 169.254.169.25 which is included in the FILTER_FLAG_NO_RES_RANGE. Google cloud metadata tho, can be accessed with http://metadata.google.internal which is not in any checks from above. And the alibaba metadata can be accessed with 100.100.100.200, this ip is neither in the FILTER_FLAG_NO_PRIV_RANGE or FILTER_FLAG_NO_RES_RANGE flags, also bypassing the check.
This make it vulnerable to ssrf when the nextcloud host is hosted with either google cloud or alibaba
Impact
SSRF filter bypass
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the address filter only checked for localhost names, hostname-only strings and private/reserved IP ranges, so it did not cover cloud metadata hostnames and addresses outside those ranges.
Impact
On a Nextcloud host running in Google Cloud or Alibaba Cloud, an attacker could use the unfiltered metadata endpoint to reach internal metadata services, though the text does not demonstrate a full exploit.
What the attacker needed
Nextcloud hosted on GCP or Alibaba Cloud; Attacker can supply a URL to be fetched
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
SSRF is when an app fetches an attacker-chosen URL, letting the server reach internal services. The filter blocked some internal addresses but missed the Google and Alibaba metadata addresses.
What is SSRF?
The server can be made to fetch an address the attacker chooses, reaching internal services, cloud metadata or other customers' data.