Update index.php

This commit is contained in:
Namhyeon Go 2025-03-11 14:42:32 +09:00
parent b7f9b96bc4
commit 4eea005aa0

View File

@ -480,25 +480,37 @@ function relay_fetch_url($params) {
// from local source // from local source
$local_prefix = "file:"; $local_prefix = "file:";
$pos = strpos($url, $local_prefix); $pos = strpos($url, $local_prefix);
if ($pos !== false && $pos == 0) { if ($pos !== false && $pos === 0) {
$path = substr($url, strlen($local_prefix)); $path = realpath(substr($url, strlen($local_prefix)));
$basedir = realpath(__DIR__);
if (file_exists($path)) { if ($path && strpos($path, $basedir) === 0) {
$response = file_get_contents($path); if (file_exists($path)) {
return array( $response = file_get_contents($path);
"success" => true, return array(
"result" => array( "success" => true,
"status" => 200, "result" => array(
"data" => $response "status" => 200,
) "data" => $response
); )
);
} else {
return array(
"success" => false,
"error" => array(
"status" => 404,
"code" => -1,
"message" => "Not found"
)
);
}
} else { } else {
return array( return array(
"success" => false, "success" => false,
"error" => array( "error" => array(
"status" => 404, "status" => 403,
"code" => -1, "code" => -1,
"message" => "Not found" "message" => "Access denied"
) )
); );
} }