39 lines
2.2 KiB
PHP
39 lines
2.2 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* Prüft, dass DeskHub nirgends in einem Rahmen (iframe) eingebettet werden darf: Die PHP-Seiten senden X-Frame-Options DENY und
|
|
* frame-ancestors 'none', und die .htaccess überschreibt das nicht mit einer schwächeren Einstellung (früher SAMEORIGIN).
|
|
*/
|
|
$root = dirname(__DIR__);
|
|
$failures = [];
|
|
$check = function (bool $ok, string $what) use (&$failures): void { if (!$ok) $failures[] = $what; };
|
|
|
|
$bootstrap = (string) file_get_contents($root . '/includes/bootstrap.php');
|
|
$check(str_contains($bootstrap, "header('X-Frame-Options: DENY');"), 'bootstrap.php sendet X-Frame-Options: DENY');
|
|
$check(str_contains($bootstrap, "frame-ancestors 'none'"), "bootstrap.php sendet frame-ancestors 'none'");
|
|
|
|
$htaccess = (string) file_get_contents($root . '/.htaccess');
|
|
$check(preg_match('/^Header always set X-Frame-Options "DENY"$/m', $htaccess) === 1, '.htaccess setzt X-Frame-Options auf DENY');
|
|
$check(stripos($htaccess, 'SAMEORIGIN') === false, '.htaccess enthält kein SAMEORIGIN mehr');
|
|
$check(!preg_match('/^Header always set Content-Security-Policy/m', $htaccess), '.htaccess ersetzt die Content-Security-Policy der Anwendung nicht');
|
|
|
|
// Keine Seite darf die Rahmen-Header selbst lockern
|
|
$loosened = [];
|
|
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root, FilesystemIterator::SKIP_DOTS));
|
|
foreach ($it as $f) {
|
|
$p = str_replace(chr(92), '/', $f->getPathname());
|
|
if (substr($p, -4) !== '.php' || preg_match('#/(tests|tools|backups|uploads|plugins)/#', $p)) continue;
|
|
$src = (string) file_get_contents($p);
|
|
$weakXfo = preg_match_all('/header\(\s*[\'"]X-Frame-Options:\s*([A-Za-z-]+)/i', $src, $m1) && array_filter($m1[1], fn($v) => strtoupper($v) !== 'DENY');
|
|
$weakCsp = preg_match_all('/frame-ancestors\s+([^;\'"]+|\'[a-z-]+\')/i', $src, $m2) && array_filter($m2[1], fn($v) => trim($v) !== "'none'");
|
|
if ($weakXfo || $weakCsp) $loosened[] = substr($p, strlen($root) + 1);
|
|
}
|
|
$check(!$loosened, 'Keine Seite lockert den Rahmenschutz: ' . implode(', ', $loosened));
|
|
|
|
if ($failures) {
|
|
fwrite(STDERR, "Fehlgeschlagen:\n - " . implode("\n - ", $failures) . "\n");
|
|
exit(1);
|
|
}
|
|
echo "Rahmenschutz (iframe) bestanden.\n";
|