Skip to content

Commit 0e56382

Browse files
author
Daniel Neto
committed
fix: enhance SSRF protection by validating redirect URLs and preventing access to restricted networks
GHSA-9x67-f2v7-63rw
1 parent b3fa786 commit 0e56382

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

plugin/LiveLinks/proxy.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
'http' => array(
2929
'user_agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36',
3030
"method" => "GET",
31-
"header" => array("Referer: localhost\r\nAccept-languange: en\r\nCookie: foo=bar\r\n")
31+
"header" => array("Referer: localhost\r\nAccept-languange: en\r\nCookie: foo=bar\r\n"),
32+
'follow_location' => 0,
33+
'max_redirects' => 0,
3234
)
3335
);
3436
$context = stream_context_create($options);
@@ -37,7 +39,23 @@
3739

3840
$headers = get_headers($_GET['livelink'], 1, $context);
3941
if (!empty($headers["Location"])) {
40-
$_GET['livelink'] = $headers["Location"];
42+
$redirectUrl = $headers["Location"];
43+
44+
// Validate the redirect target URL format and scheme before SSRF check
45+
if (!filter_var($redirectUrl, FILTER_VALIDATE_URL) || !preg_match("/^https?:\/\//i", $redirectUrl)) {
46+
_error_log("LiveLinks proxy: invalid redirect URL: " . $redirectUrl);
47+
echo "Access denied: Invalid redirect URL";
48+
exit;
49+
}
50+
51+
// SSRF Protection: Re-validate redirect target against internal/private networks
52+
if (!isSSRFSafeURL($redirectUrl)) {
53+
_error_log("LiveLinks proxy: SSRF protection blocked redirect URL: " . $redirectUrl);
54+
echo "Access denied: Redirect URL targets restricted network";
55+
exit;
56+
}
57+
58+
$_GET['livelink'] = $redirectUrl;
4159
$urlinfo = parse_url($_GET['livelink']);
4260
$content = fakeBrowser($_GET['livelink']);
4361
$_GET['livelink'] = "{$urlinfo["scheme"]}://{$urlinfo["host"]}:{$urlinfo["port"]}";

0 commit comments

Comments
 (0)