|
12 | 12 | class UnraidCheckExec |
13 | 13 | { |
14 | 14 | private const SCRIPT_PATH = '/usr/local/emhttp/plugins/dynamix.plugin.manager/scripts/unraidcheck'; |
| 15 | + private const ALLOWED_DOMAIN = 'releases.unraid.net'; |
15 | 16 |
|
16 | 17 | private function setupEnvironment(): void |
17 | 18 | { |
18 | 19 | header('Content-Type: application/json'); |
| 20 | + header('X-Content-Type-Options: nosniff'); |
| 21 | + header('X-Frame-Options: DENY'); |
| 22 | + header('Content-Security-Policy: default-src \'none\''); |
19 | 23 |
|
20 | 24 | $params = [ |
21 | 25 | 'json' => 'true', |
22 | 26 | ]; |
23 | | - // allows the web components to determine the OS_RELEASES url |
24 | | - if (isset($_GET['altUrl']) && filter_var($_GET['altUrl'], FILTER_VALIDATE_URL)) { |
25 | | - $params['altUrl'] = $_GET['altUrl']; |
| 27 | + |
| 28 | + if (isset($_GET['altUrl'])) { |
| 29 | + $url = filter_var($_GET['altUrl'], FILTER_VALIDATE_URL); |
| 30 | + if ($url !== false) { |
| 31 | + $host = parse_url($url, PHP_URL_HOST); |
| 32 | + $scheme = parse_url($url, PHP_URL_SCHEME); |
| 33 | + |
| 34 | + if ($host && $scheme === 'https' && ( |
| 35 | + $host === self::ALLOWED_DOMAIN || |
| 36 | + str_ends_with($host, '.' . self::ALLOWED_DOMAIN) |
| 37 | + )) { |
| 38 | + $params['altUrl'] = $url; |
| 39 | + } |
| 40 | + } |
26 | 41 | } |
27 | | - // pass the params to the unraidcheck script for usage in UnraidCheck.php |
| 42 | + |
28 | 43 | putenv('QUERY_STRING=' . http_build_query($params)); |
29 | 44 | } |
30 | 45 |
|
31 | 46 | public function execute(): string |
32 | 47 | { |
33 | | - if (!is_file(self::SCRIPT_PATH) || !is_readable(self::SCRIPT_PATH)) { |
34 | | - throw new RuntimeException('Script not found or not readable'); |
| 48 | + // Validate script with all necessary permissions |
| 49 | + if (!is_file(self::SCRIPT_PATH) || |
| 50 | + !is_readable(self::SCRIPT_PATH) || |
| 51 | + !is_executable(self::SCRIPT_PATH)) { |
| 52 | + throw new RuntimeException('Script not found or not executable'); |
35 | 53 | } |
36 | 54 |
|
37 | 55 | $this->setupEnvironment(); |
38 | 56 | $output = []; |
39 | 57 | $command = escapeshellcmd(self::SCRIPT_PATH); |
40 | | - exec($command, $output); |
| 58 | + if (exec($command, $output) === false) { |
| 59 | + throw new RuntimeException('Script execution failed'); |
| 60 | + } |
41 | 61 |
|
42 | 62 | return implode("\n", $output); |
43 | 63 | } |
|
0 commit comments