Fix findings of the full security and bug scan
- Update Symfony to 7.4.24/25 and Twig to 3.31.1 (19 advisories), npm ws - Forms: honeypot no longer named "website" (a field labelled Website silently dropped every submission), reserve technical field names, keep single-line fields on one line - Installer: English installations stored pages under "en" and served 404 - Schedules from before ADR 116 no longer publish the latest draft - Moving a page: refuse reserved addresses, claim the version atomically - Content packages: check close(), require all media, verify extracted bytes, clean up on failure, clear the media mirror after import - Updater: failed copies in public/ and plugins/ abort and roll back public/ - Restore: missing media fail the restore; cms:restore keeps maintenance on - Editor preview honours the page's header and footer choice Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4a33090905
commit
33dc413ef6
22 files changed
+659
-246
No files matched your search
@@ -156,6 +156,26 @@ final class ArchiveUpdateTest extends TestCase
|
||||
self::assertFileDoesNotExist($this->root.'/'.Updater::MAINTENANCE_FILE, 'Die Website darf davon nichts merken.');
|
||||
}
|
||||
|
||||
public function testAFileInPublicThatCannotBeReplacedSwitchesEverythingBack(): void
|
||||
{
|
||||
// public/index.php lässt sich nicht überschreiben (hier: ein Ordner an ihrer Stelle; live
|
||||
// fehlende Schreibrechte oder volle Platte). Vorher meldete das Update trotzdem Erfolg und
|
||||
// ließ neuen Code mit altem public/ stehen; ein Fehler danach brachte public/ nicht zurück.
|
||||
unlink($this->root.'/public/index.php');
|
||||
mkdir($this->root.'/public/index.php');
|
||||
$this->releases->release(self::BASE, self::API, '1.1.0', $this->archive('1.1.0'));
|
||||
|
||||
$ergebnis = $this->updater()->run();
|
||||
|
||||
self::assertFalse($ergebnis['ok']);
|
||||
self::assertSame('Dateien ersetzen', $this->firstFailed($ergebnis)['step'], $this->explain($ergebnis));
|
||||
self::assertSame('1.0.0', trim((string) file_get_contents($this->root.'/VERSION')));
|
||||
self::assertFileExists($this->root.'/src/Alt.php');
|
||||
self::assertSame('body{color:alt}', file_get_contents($this->root.'/public/assets/site.css'), 'Schon ersetzte Dateien in public/ kommen zurück.');
|
||||
self::assertNull($this->updater()->pending());
|
||||
self::assertFileDoesNotExist($this->root.'/'.Updater::MAINTENANCE_FILE);
|
||||
}
|
||||
|
||||
public function testAnIncompleteArchiveIsRefusedBeforeTheSiteGoesIntoMaintenance(): void
|
||||
{
|
||||
// Ein Archiv ohne vendor/ ist auf einem Hosting ohne Composer wertlos - das muss auffallen,
|
||||
|
||||
@@ -143,6 +143,25 @@ final class BackupTest extends TestCase
|
||||
self::assertFileExists($this->root.'/var/media/bild-480.webp');
|
||||
}
|
||||
|
||||
public function testAMediaFileThatCannotBeWrittenBackFailsTheRestore(): void
|
||||
{
|
||||
$backup = $this->backup->create('Test');
|
||||
// Die Datei lässt sich nicht zurückschreiben (hier: ein Ordner an ihrer Stelle; live
|
||||
// fehlende Schreibrechte). Vorher zählte die Wiederherstellung sie still nicht mit und
|
||||
// meldete Erfolg, obwohl die Datenbank auf das Bild verweist.
|
||||
unlink($this->root.'/var/media/bild-480.webp');
|
||||
mkdir($this->root.'/var/media/bild-480.webp');
|
||||
|
||||
$result = $this->backup->restore($backup['name']);
|
||||
rmdir($this->root.'/var/media/bild-480.webp');
|
||||
|
||||
self::assertFalse($result['ok']);
|
||||
$media = array_values(array_filter($result['steps'], static fn (array $s): bool => 'Medien ergänzen' === $s['step']))[0] ?? null;
|
||||
self::assertNotNull($media);
|
||||
self::assertFalse($media['ok']);
|
||||
self::assertStringContainsString('bild-480.webp', $media['detail']);
|
||||
}
|
||||
|
||||
public function testATamperedBackupIsNotRestored(): void
|
||||
{
|
||||
$backup = $this->backup->create('Test');
|
||||
|
||||
@@ -2991,6 +2991,21 @@ final class CmsTest extends TestCase
|
||||
self::assertSame($child, $this->db->fetchOne('SELECT parent_id FROM page WHERE id = ?', [$grandchild]));
|
||||
}
|
||||
|
||||
public function testAMoveThatLostTheRaceForTheVersionChangesNothing(): void
|
||||
{
|
||||
// Zwei gleichzeitige Verschiebungen lesen dieselbe Version. Nachgestellt: die erste ist
|
||||
// schon durch, die zweite kommt mit der alten Version und darf nicht überschreiben.
|
||||
$page = $this->publishedPage('beratung', 'Beratung');
|
||||
$version = $this->pages->findForEditor($page)['version'];
|
||||
$this->db->executeStatement('UPDATE page SET version = version + 1 WHERE id = ?', [$page]);
|
||||
try {
|
||||
$this->pages->movePage($page, 'anders', null, $version, $this->redirects);
|
||||
self::fail('Expected a stale write.');
|
||||
} catch (StaleWrite) {
|
||||
}
|
||||
self::assertSame('beratung', $this->db->fetchOne('SELECT path FROM page WHERE id = ?', [$page]));
|
||||
}
|
||||
|
||||
public function testMoveRefusesCyclesCollisionsAndTheHomePage(): void
|
||||
{
|
||||
$parent = $this->publishedPage('leistungen', 'Leistungen');
|
||||
@@ -3002,6 +3017,9 @@ final class CmsTest extends TestCase
|
||||
'into itself' => [$parent, 'leistungen', $parent],
|
||||
'onto a taken address' => [$other, 'leistungen', null],
|
||||
'with a slug that is no slug' => [$other, 'mit leerzeichen', null],
|
||||
// Beim Anlegen schon gesperrt, beim Verschieben fehlte die Prüfung.
|
||||
'onto the administration' => [$other, 'admin', null],
|
||||
'onto the media address' => [$other, 'media', null],
|
||||
];
|
||||
foreach ($cases as $name => [$page, $slug, $target]) {
|
||||
try {
|
||||
@@ -3869,6 +3887,12 @@ display: flex', '#b1{display:flex;color:red}'];
|
||||
// sonst lieferte der Webserver weiter aus, was die Anwendung nicht mehr kennt.
|
||||
$mirror = new \App\Content\MediaMirror($abbild, $this->path.'-media');
|
||||
self::assertSame(0, $mirror->prune());
|
||||
// Bringt ein Paket dieselbe Kennung mit anderem Inhalt, findet prune() nichts; deshalb
|
||||
// leert der Import das Abbild ganz, und es füllt sich beim nächsten Abruf wieder.
|
||||
self::assertSame(1, $mirror->clear());
|
||||
self::assertDirectoryDoesNotExist($abbild.'/'.$item['id']);
|
||||
$mirror->publish($item['id'], 480, $quelle);
|
||||
self::assertFileEquals($quelle, $ziel);
|
||||
unlink($quelle);
|
||||
file_put_contents($abbild.'/'.$item['id'].'/fremd.txt', 'gehört nicht hierher');
|
||||
self::assertSame(2, $mirror->prune());
|
||||
|
||||
@@ -227,6 +227,23 @@ final class EditorSecurityTest extends WebTestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testThePreviewHonoursThePagesChoiceOfHeader(): void
|
||||
{
|
||||
// Eine Landingpage ohne Kopf: die Website zeigt keinen, die Vorschau zeigte trotzdem den Standardkopf.
|
||||
$client = $this->login();
|
||||
$data = $this->data($client);
|
||||
$preview = function () use ($client, $data): string {
|
||||
$this->post($client, 'preview', ['document' => $data['document'], 'expectedVersion' => $data['version']], $data['csrfToken']);
|
||||
self::assertResponseIsSuccessful();
|
||||
|
||||
return (string) $client->getResponse()->getContent();
|
||||
};
|
||||
self::assertStringContainsString('area-header', $preview());
|
||||
$this->db->executeStatement("UPDATE page SET header_area = 'none' WHERE id = ?", ['p1']);
|
||||
self::assertStringNotContainsString('area-header', $preview());
|
||||
self::assertStringContainsString('area-footer', $preview(), 'Der Fuß bleibt, wo nur der Kopf abgewählt ist.');
|
||||
}
|
||||
|
||||
private function data(KernelBrowser $client): array
|
||||
{
|
||||
$client->request('GET', '/admin/api/pages/p1');
|
||||
@@ -418,6 +435,24 @@ final class EditorSecurityTest extends WebTestCase
|
||||
self::assertNull($this->db->fetchOne('SELECT publish_revision_id FROM page WHERE id = ?', [$id]));
|
||||
}
|
||||
|
||||
public function testAScheduleFromBeforeTheRevisionColumnDoesNotPublishTheLatestDraft(): void
|
||||
{
|
||||
// Ein Termin aus der Zeit vor ADR 116: publish_at gesetzt, keine Fassung festgehalten.
|
||||
// Danach speichert ein Redakteur einen ungeprüften Entwurf - der ging früher zum Termin online.
|
||||
$pages = new PageRepository($this->db, new DocumentValidator(), new SiteSettings($this->db, new MediaLibrary($this->db, $this->path.'-media')));
|
||||
$id = $pages->createPage('alt-termin', null, 'page', DemoContent::starter('Ungeprüft'));
|
||||
$this->db->executeStatement('UPDATE page SET publish_at = ? WHERE id = ?', ['2026-01-01 08:00:00', $id]);
|
||||
|
||||
$log = ini_set('error_log', \PHP_OS_FAMILY === 'Windows' ? 'NUL' : '/dev/null');
|
||||
try {
|
||||
self::assertSame([], $pages->publishDue());
|
||||
} finally {
|
||||
ini_set('error_log', (string) $log);
|
||||
}
|
||||
self::assertNull($this->db->fetchOne('SELECT published_revision_id FROM page WHERE id = ?', [$id]));
|
||||
self::assertNull($this->db->fetchOne('SELECT publish_at FROM page WHERE id = ?', [$id]), 'Der Termin verfällt, statt ewig fällig zu bleiben.');
|
||||
}
|
||||
|
||||
public function testAdministratorsDeleteAPageWithAllRevisionsOnlyWithACsrfToken(): void
|
||||
{
|
||||
$client = $this->login('admin');
|
||||
@@ -560,7 +595,7 @@ final class EditorSecurityTest extends WebTestCase
|
||||
private function validBody(string $issued): array
|
||||
{
|
||||
return [
|
||||
'page' => 'home', 'block' => 'formblock', 'website' => '',
|
||||
'page' => 'home', 'block' => 'formblock', FormRepository::HONEYPOT => '',
|
||||
'issued' => $issued, 'issuedSignature' => FormRepository::stamp('kontakt', (int) $issued, 'isolated-test-secret'),
|
||||
'name' => 'Umut', 'email' => 'umut@example.com', 'thema' => 'Beratung',
|
||||
'nachricht' => 'Bitte um Rückruf.', 'datenschutz' => 'ja',
|
||||
@@ -578,7 +613,7 @@ final class EditorSecurityTest extends WebTestCase
|
||||
self::assertStringContainsString('<button class="button cms-button" type="submit">Absenden</button>', $html);
|
||||
self::assertStringContainsString('Ich willige ein.', $html);
|
||||
// The honeypot exists but is kept out of the tab order and away from assistive technology.
|
||||
self::assertStringContainsString('name="website"', $html);
|
||||
self::assertStringContainsString('name="'.FormRepository::HONEYPOT.'"', $html);
|
||||
self::assertStringContainsString('tabindex="-1"', $html);
|
||||
self::assertStringNotContainsString('<script', $client->getResponse()->getContent());
|
||||
|
||||
@@ -674,7 +709,9 @@ final class EditorSecurityTest extends WebTestCase
|
||||
public static function droppedSubmissions(): iterable
|
||||
{
|
||||
$sign = static fn (string $issued): string => FormRepository::stamp('kontakt', (int) $issued, 'isolated-test-secret');
|
||||
yield 'honeypot filled' => [static fn (array $body): array => [...$body, 'website' => 'https://spam.example']];
|
||||
yield 'honeypot filled' => [static fn (array $body): array => [...$body, FormRepository::HONEYPOT => 'https://spam.example']];
|
||||
// Eine Seite aus dem Zwischenspeicher trägt noch den alten Namen des Honigtopfs.
|
||||
yield 'old honeypot filled' => [static fn (array $body): array => [...$body, 'website' => 'https://spam.example']];
|
||||
yield 'submitted too fast' => [static fn (array $body): array => [...$body, 'issued' => (string) time(), 'issuedSignature' => $sign((string) time())]];
|
||||
yield 'timestamp forged' => [static fn (array $body): array => [...$body, 'issuedSignature' => 'nicht-signiert']];
|
||||
yield 'timestamp far in the past' => [static function (array $body) use ($sign): array {
|
||||
@@ -697,6 +734,40 @@ final class EditorSecurityTest extends WebTestCase
|
||||
self::assertSame(0, (int) $this->db->fetchOne('SELECT COUNT(*) FROM form_submission'));
|
||||
}
|
||||
|
||||
public function testAFieldNamedWebsiteIsAnsweredNotMistakenForTheHoneypot(): void
|
||||
{
|
||||
// Der Editor macht aus der Beschriftung „Website“ den Namen „website“ - so hieß früher der
|
||||
// Honigtopf, und jede Anfrage mit ausgefüllter Adresse verschwand still.
|
||||
$forms = new FormRepository($this->db);
|
||||
$forms->save('kontakt', 'Kontakt', [
|
||||
['name' => 'email', 'type' => 'email', 'label' => 'E-Mail', 'required' => true],
|
||||
['name' => 'website', 'type' => 'text', 'label' => 'Website', 'required' => false],
|
||||
['name' => 'name', 'type' => 'text', 'label' => 'Name', 'required' => false],
|
||||
], ['recipient' => 'info@kant-it.de', 'subject' => 'Anfrage', 'success' => 'Danke.'], 0);
|
||||
$this->pageWithForm();
|
||||
$client = self::createClient();
|
||||
|
||||
$body = [...$this->validBody((string) (time() - 10)), 'website' => 'https://kunde.example', 'name' => "Max\nE-Mail: chef@firma.example"];
|
||||
$client->request('POST', '/formular/kontakt', $body);
|
||||
self::assertResponseStatusCodeSame(303);
|
||||
$data = json_decode((string) $this->db->fetchOne('SELECT data FROM form_submission'), true);
|
||||
self::assertSame('https://kunde.example', $data['website'] ?? null);
|
||||
// Ein einzeiliges Feld bleibt einzeilig und kann keine Zeile der Benachrichtigung fälschen.
|
||||
self::assertSame('Max E-Mail: chef@firma.example', $data['name'] ?? null);
|
||||
}
|
||||
|
||||
public function testNamesTheFormSendsItselfAreRefusedAsFieldNames(): void
|
||||
{
|
||||
foreach (FormRepository::RESERVED_NAMES as $name) {
|
||||
try {
|
||||
(new FormRepository($this->db))->save('reserviert-'.$name, 'Reserviert', [['name' => $name, 'type' => 'text', 'label' => 'Feld']], ['recipient' => 'info@kant-it.de'], 0);
|
||||
self::fail($name.' wurde als Feldname angenommen.');
|
||||
} catch (InvalidForm $e) {
|
||||
self::assertStringContainsString('reserviert', $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testRateLimitStopsTheSixthSubmissionWithinAnHour(): void
|
||||
{
|
||||
$forms = $this->contactForm();
|
||||
|
||||
@@ -207,6 +207,20 @@ final class InstallationTest extends TestCase
|
||||
yield 'Tippfehler bei der Wiederholung' => ['chefin', 'ein sehr langes passwort', 'ein sehr langes passwortt'];
|
||||
}
|
||||
|
||||
public function testAnEnglishInstallationServesItsPages(): void
|
||||
{
|
||||
// Englisch stand im Installer zur Wahl, und danach antwortete jede Seite mit 404: die
|
||||
// Seiten lagen unter „en“, gelesen wird die Hauptsprache unter „de“ (ADR 111).
|
||||
$this->installation->migrate();
|
||||
$this->installation->createSite('Example Ltd', 'https://example.com', 'en');
|
||||
|
||||
$pages = new PageRepository($this->db, new DocumentValidator(), new SiteSettings($this->db, new MediaLibrary($this->db, $this->root.'/var/media')));
|
||||
self::assertNotNull($pages->findPublished('home'), 'Die Startseite einer englischen Installation fehlt.');
|
||||
self::assertNotNull($pages->findPublished('impressum'));
|
||||
self::assertSame('en', $this->db->fetchOne('SELECT default_locale FROM website'));
|
||||
self::assertSame(['de'], $this->db->fetchFirstColumn('SELECT DISTINCT locale FROM page'));
|
||||
}
|
||||
|
||||
#[DataProvider('badSites')]
|
||||
public function testAWebsiteWithBadInputIsRefused(string $name, string $origin, string $locale): void
|
||||
{
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use App\Command\RestoreCommand;
|
||||
use App\Infrastructure\ConnectionFactory;
|
||||
use App\Ops\Backup;
|
||||
use App\Ops\CommandRunner;
|
||||
use App\Ops\Updater;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
/**
|
||||
* cms:restore schaltet die Wartung nur ab, wenn es sie selbst eingeschaltet hat.
|
||||
*
|
||||
* Vorher hob der Befehl eine Wartung immer auf - auch die eines offenen Updates oder eine, die
|
||||
* jemand mit Absicht eingeschaltet hatte. Eine halb geschaltete Installation ging damit live.
|
||||
*/
|
||||
final class RestoreCommandTest extends TestCase
|
||||
{
|
||||
private string $root;
|
||||
private Connection $db;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->root = str_replace('\\', '/', sys_get_temp_dir()).'/kant-restore-'.bin2hex(random_bytes(6));
|
||||
mkdir($this->root.'/var/media', 0o775, true);
|
||||
file_put_contents($this->root.'/VERSION', "1.0.0\n");
|
||||
$this->db = ConnectionFactory::create('sqlite:///'.$this->root.'/var/cms.db');
|
||||
TestSchema::build($this->db);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->db->close();
|
||||
gc_collect_cycles();
|
||||
self::remove($this->root);
|
||||
}
|
||||
|
||||
public function testAMaintenanceStateThatWasAlreadyOnStaysOn(): void
|
||||
{
|
||||
file_put_contents($this->root.'/'.Updater::MAINTENANCE_FILE, "an\n");
|
||||
$this->command()->execute(['name' => 'sicherung-gibt-es-nicht'], ['interactive' => false]);
|
||||
self::assertFileExists($this->root.'/'.Updater::MAINTENANCE_FILE);
|
||||
}
|
||||
|
||||
public function testAMaintenanceStateTheCommandSwitchedOnIsSwitchedOffAgain(): void
|
||||
{
|
||||
$this->command()->execute(['name' => 'sicherung-gibt-es-nicht'], ['interactive' => false]);
|
||||
self::assertFileDoesNotExist($this->root.'/'.Updater::MAINTENANCE_FILE);
|
||||
}
|
||||
|
||||
private function command(): CommandTester
|
||||
{
|
||||
$runner = new CommandRunner();
|
||||
$url = 'sqlite:///'.$this->root.'/var/cms.db';
|
||||
|
||||
return new CommandTester(new RestoreCommand(
|
||||
new Backup($this->root, $url, $this->root.'/var/media', $this->db, $runner),
|
||||
new Updater($this->root, $url, $runner, $this->db),
|
||||
));
|
||||
}
|
||||
|
||||
private static function remove(string $path): void
|
||||
{
|
||||
foreach (glob($path.'/{,.}[!.]*', GLOB_BRACE) ?: [] as $entry) {
|
||||
is_dir($entry) ? self::remove($entry) : @unlink($entry);
|
||||
}
|
||||
@rmdir($path);
|
||||
}
|
||||
}
|
||||
@@ -132,6 +132,9 @@ final class SitePackageTest extends TestCase
|
||||
{
|
||||
yield 'fremde Datei' => [static fn (\ZipArchive $zip) => $zip->addFromString('../../public/hallo.php', '<?php'), 'gehört nicht in ein Inhaltspaket'];
|
||||
yield 'Skript als Medium' => [static fn (\ZipArchive $zip) => $zip->addFromString('medien/shell.php', '<?php'), 'gehört nicht in ein Inhaltspaket'];
|
||||
// Ein Paket, dem beim Schreiben die Medien verloren gingen: ohne Prüfung löschte der
|
||||
// Import die Bilder der Zielwebsite und ersetzte sie durch nichts.
|
||||
yield 'fehlende Mediendatei' => [static fn (\ZipArchive $zip) => $zip->deleteName(SitePackage::MEDIA.str_repeat('a', 32).'-480.webp'), 'fehlen Mediendateien'];
|
||||
yield 'veränderter Inhalt' => [static function (\ZipArchive $zip): void {
|
||||
$zip->addFromString(SitePackage::DATA, str_replace('Seite der quelle', 'Untergeschoben', (string) $zip->getFromName(SitePackage::DATA)));
|
||||
}, 'Prüfsumme'];
|
||||
|
||||
Reference in new issue
Block a user