|
28 | 28 | 'http' => array( |
29 | 29 | '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', |
30 | 30 | "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, |
32 | 34 | ) |
33 | 35 | ); |
34 | 36 | $context = stream_context_create($options); |
|
37 | 39 |
|
38 | 40 | $headers = get_headers($_GET['livelink'], 1, $context); |
39 | 41 | 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; |
41 | 59 | $urlinfo = parse_url($_GET['livelink']); |
42 | 60 | $content = fakeBrowser($_GET['livelink']); |
43 | 61 | $_GET['livelink'] = "{$urlinfo["scheme"]}://{$urlinfo["host"]}:{$urlinfo["port"]}"; |
|
0 commit comments