Skip to content

LibreY Server-Side Request Forgery (SSRF) vulnerability via wikipedia_language cookie

High
Ahwxorg published GHSA-xfj6-4vp9-8rgc Sep 3, 2023

Package

LibreX

Affected versions

<= b5a9f12df91cb8ded541df291da58ce2f104fe62

Patched versions

None
LibreY
< be59098abd119cda70b15bf3faac596dfd39a744
>= be59098abd119cda70b15bf3faac596dfd39a744

Description

Summary

Server-Side Request Forgery (SSRF) vulnerability in engines/google/text.php and engines/duckduckgo/text.php before commit be59098 allows remote attackers to request the server to send HTTP GET requests to arbitrary targets and conduct Denial-of-Service (DoS) attacks via the wikipedia_language cookie.

Details

In engines/google/text.php, the wikipedia_language cookie is used as the first part of the URL where a GET request is sent to.

case 7:
$wikipedia_language = isset($_COOKIE["wikipedia_language"]) ? trim(htmlspecialchars($_COOKIE["wikipedia_language"])) : $config->wikipedia_language;
$url = "https://$wikipedia_language.wikipedia.org/w/api.php?format=json&action=query&prop=extracts%7Cpageimages&exintro&explaintext&redirects=1&pithumbsize=500&titles=$query_encoded";
break;
}
if ($url != NULL)
{
$special_ch = curl_init($url);

If the cookie contains a slash, the domain is no longer wikipedia.org. If the cookie further ends with a hash sign, the .wikipedia.org/w/api.php?... will become the hash of the URL and the path of the request target can also be controlled by the attacker.

So the attacker can make the server send arbitrary GET requests, and DoS attacks can be conducted by requesting the server to download large files. If the server is behind a CDN, the original IP address can be disclosed via SSRF, so the DDoS protection provided by the CDN could be bypassed.

Fortunately, in engines/special/wikipedia.php, the response is decoded as JSON, so this is almost a blind SSRF where the attacker cannot see the response.

function wikipedia_results($query, $response)
{
global $config;
$query_encoded = urlencode($query);
$json_response = json_decode($response, true);
$first_page = array_values($json_response["query"]["pages"])[0];
if (!array_key_exists("missing", $first_page))
{
$description = substr($first_page["extract"], 0, 250) . "...";
$wikipedia_language = isset($_COOKIE["wikipedia_language"]) ? trim(htmlspecialchars($_COOKIE["wikipedia_language"])) : $config->wikipedia_language;
$source = check_for_privacy_frontend("https://$wikipedia_language.wikipedia.org/wiki/$query");
$response = array(
"special_response" => array(
"response" => htmlspecialchars($description),
"source" => $source
)
);
if (array_key_exists("thumbnail", $first_page))
{
$image_url = $first_page["thumbnail"]["source"];
$response["special_response"]["image"] = $image_url;
}
return $response;
}
}

PoC

SSRF

  1. Get a URL at https://requestrepo.com/, e.g. xxx.requestrepo.com.
  2. Set wikipedia_language to xxx.requestrepo.com/foo#.
  3. Search "bar".
  4. Observe a request for https://xxx.requestrepo.com/foo at https://requestrepo.com/.

DoS

Send requests to /search.php?q=dos with header Cookie: wikipedia_language=speed.hetzner.de/100MB.bin# multiple times, and then send normal requests to see long response time or errors.

Impact

Remote attackers can request the server to download large files to reduce the performance of the server or even deny access from legitimate users.

Remote attackers can get the IP address of the server even if it is behind a CDN.

Patches

This has been fixed in #9.

LibreY hosters are advised to use the latest commit, and LibreX hosters are advised to migrate to LibreY.

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
None
User interaction
None
Scope
Unchanged
Confidentiality
None
Integrity
None
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H

CVE ID

CVE-2023-41055

Credits