Fix hard-coded path issues that stopped flags from showing

This commit is contained in:
Andy Taylor 2025-10-21 10:32:25 +01:00
parent f82e2eb898
commit e21fa2e404

View file

@ -149,9 +149,28 @@ class xReflector {
} }
public function SetFlagFile($Flagfile) { public function SetFlagFile($Flagfile) {
// Prevent path traversal // Prevent path traversal - get the real path
$realPath = realpath($Flagfile); $realPath = realpath($Flagfile);
if ($realPath === false || strpos($realPath, '/dashboard/pgs/') === false) {
// If realpath fails, the file doesn't exist
if ($realPath === false) {
error_log("Flag file does not exist: " . $Flagfile);
return false;
}
// Security: Ensure it's the country.csv file we expect
if (basename($realPath) !== 'country.csv') {
error_log("Flag file must be country.csv, got: " . basename($realPath));
return false;
}
// Security: Ensure the file is in the same directory as this class file or subdirectory
$thisDir = dirname(__FILE__); // Gets /path/to/pgs
$thisDirReal = realpath($thisDir);
// The flag file must be in the same directory as this class
if (dirname($realPath) !== $thisDirReal) {
error_log("Flag file must be in the same directory as class files. Expected: " . $thisDirReal . ", Got: " . dirname($realPath));
return false; return false;
} }
@ -159,6 +178,8 @@ class xReflector {
$this->Flagfile = $realPath; $this->Flagfile = $realPath;
return true; return true;
} }
error_log("Flag file not readable: " . $realPath);
return false; return false;
} }