- Fixed a missing variable bug

This commit is contained in:
Dave M. 2026-07-07 12:42:25 +00:00
parent 4834404575
commit 6b1be4d245
2 changed files with 24 additions and 7 deletions

View File

@ -14,20 +14,20 @@ class File
$beginning = false; $beginning = false;
$text = array(); $text = array();
while ($counter && ! $beginning) { while ($counter && !$beginning) {
$t = ""; $t = "";
while ($t !== PHP_EOL) { while ($t !== PHP_EOL) {
if(fseek($handle, $pos, SEEK_END) == -1) { if (fseek($handle, $pos, SEEK_END) == -1) {
$beginning = true; $beginning = true;
break; break;
} }
$t = fgetc($handle); $t = fgetc($handle);
$pos --; $pos--;
} }
$counter --; $counter--;
if ($beginning) { if ($beginning) {
rewind($handle); rewind($handle);
@ -36,8 +36,26 @@ class File
$text[$lines - $counter - 1] = fgets($handle); $text[$lines - $counter - 1] = fgets($handle);
} }
fclose ($handle); fclose($handle);
return array_reverse($text); return array_reverse($text);
} }
public static function sanitizeFilePath($path) : string
{
// Remove null bytes
$path = str_replace("\0", "", $path);
$path = str_replace([ "\\", "/" ], DIRECTORY_SEPARATOR, $path);
$path = preg_replace('#' . DIRECTORY_SEPARATOR . '+#', DIRECTORY_SEPARATOR, $path);
// Remove . and .. directory traversal attempts
$path = preg_replace('#\.{1,2}/#', '', $path);
$path = trim($path, '/\\');
return $path;
}
} }

View File

@ -58,10 +58,9 @@ class Kernel
if (($keys = getenv('KEYS')) && ($auth = $_SERVER["HTTP_X_DEV_AUTH"] ?? null) && in_array($auth, explode(',', $keys))) { if (($keys = getenv('KEYS')) && ($auth = $_SERVER["HTTP_X_DEV_AUTH"] ?? null) && in_array($auth, explode(',', $keys))) {
unset($_SERVER["HTTP_X_DEV_AUTH"]); unset($_SERVER["HTTP_X_DEV_AUTH"]);
unset($_ENV[$name], $_SERVER[$name]); unset($_ENV['KEYS'], $_SERVER['KEYS']);
putenv("KEYS="); putenv("KEYS=");
foreach(['APP_ENV', 'DEBUG',] as $env) { foreach(['APP_ENV', 'DEBUG',] as $env) {
if (null !== $value = $_SERVER["HTTP_X_$env"] ?? null) { if (null !== $value = $_SERVER["HTTP_X_$env"] ?? null) {
static::putenv($env, $value); static::putenv($env, $value);