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
@@ -169,14 +169,14 @@ final class ArchiveUpdate
|
||||
|
||||
return ['ok' => true, 'steps' => $schritte];
|
||||
}
|
||||
$this->phase('sichern', 'Datenbank und Medien werden gesichert …', ['laeuft' => true, 'von' => $this->updater->version(), 'auf' => $ziel, 'seit' => gmdate('c')], true);
|
||||
|
||||
$lock = $this->updater->lock();
|
||||
if (null === $lock) {
|
||||
$melden($schritte, 'Sperre', false, 'Ein anderes Update läuft gerade (var/update.lock). Bitte warten.');
|
||||
|
||||
return ['ok' => false, 'steps' => $schritte];
|
||||
}
|
||||
// Erst mit der Sperre: ein zweiter Aufruf setzte sonst den Fortschritt des laufenden zurück.
|
||||
$this->phase('sichern', 'Datenbank und Medien werden gesichert …', ['laeuft' => true, 'von' => $this->updater->version(), 'auf' => $ziel, 'seit' => gmdate('c')], true);
|
||||
try {
|
||||
return $this->apply($schritte, $melden, $ziel, $neueste);
|
||||
} finally {
|
||||
@@ -285,6 +285,14 @@ final class ArchiveUpdate
|
||||
@rename($alt.'/'.$eintrag, $this->root.'/'.$eintrag);
|
||||
}
|
||||
}
|
||||
// Auch public/ und plugins/ zurück, soweit sie schon angefasst waren - sonst bliebe
|
||||
// der alte Code mit halb neuen Dateien in public/ stehen.
|
||||
foreach ($this->publicNeu as $relativ) {
|
||||
@unlink($this->root.'/'.$relativ);
|
||||
}
|
||||
foreach ($this->publicAlt as $relativ) {
|
||||
@copy($this->publicSicherung.'/'.$relativ, $this->root.'/'.$relativ);
|
||||
}
|
||||
$melden($schritte, 'Dateien ersetzen', false, $fehler->getMessage().' Der alte Stand wurde zurückgeschoben.');
|
||||
$this->updater->maintenance(false);
|
||||
|
||||
@@ -568,7 +576,9 @@ final class ArchiveUpdate
|
||||
continue;
|
||||
}
|
||||
if (is_dir($quelle)) {
|
||||
@mkdir($ziel, 0o775, true);
|
||||
if (!is_dir($ziel) && !@mkdir($ziel, 0o775, true)) {
|
||||
throw new \RuntimeException($ziel.' ließ sich nicht anlegen. Schreibrechte prüfen.');
|
||||
}
|
||||
$this->mergePublic($quelle, $ziel);
|
||||
|
||||
continue;
|
||||
@@ -579,7 +589,10 @@ final class ArchiveUpdate
|
||||
|
||||
continue;
|
||||
}
|
||||
@copy($quelle, $ziel);
|
||||
// Ein stilles Scheitern hinterließ neuen Code mit altem public/ und meldete Erfolg.
|
||||
if (!@copy($quelle, $ziel)) {
|
||||
throw new \RuntimeException(ltrim(substr($ziel, strlen($this->root)), '/').' ließ sich nicht ersetzen. Schreibrechte und freien Speicherplatz prüfen.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -597,9 +610,11 @@ final class ArchiveUpdate
|
||||
}
|
||||
$kopie = $this->publicSicherung.'/'.$relativ;
|
||||
@mkdir(dirname($kopie), 0o775, true);
|
||||
if (@copy($ziel, $kopie)) {
|
||||
$this->publicAlt[] = $relativ;
|
||||
// Ohne Kopie keine Überschreibung: ein Zurückschalten bekäme die Datei sonst nicht zurück.
|
||||
if (!@copy($ziel, $kopie)) {
|
||||
throw new \RuntimeException($relativ.' ließ sich nicht sichern. Freien Speicherplatz prüfen.');
|
||||
}
|
||||
$this->publicAlt[] = $relativ;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+22
-6
@@ -234,8 +234,14 @@ final class Backup
|
||||
|
||||
// Media are added, never deleted: files uploaded after the backup would otherwise be lost
|
||||
// by the very operation that is meant to prevent loss.
|
||||
$restored = $this->restoreMedia($path.'/medien');
|
||||
$step($steps, 'Medien ergänzen', true, sprintf('%d Datei(en) zurückgeschrieben. Neuere Dateien bleiben erhalten.', $restored));
|
||||
[$restored, $missing] = $this->restoreMedia($path.'/medien');
|
||||
// Eine Datei, die nicht ankam, ist ein Fehler, kein stilles Weniger: die Datenbank
|
||||
// verweist auf sie.
|
||||
if (!$step($steps, 'Medien ergänzen', [] === $missing, [] === $missing
|
||||
? sprintf('%d Datei(en) zurückgeschrieben. Neuere Dateien bleiben erhalten.', $restored)
|
||||
: sprintf('%d Datei(en) zurückgeschrieben, %d nicht (%s). Die Datenbank ist bereits zurückgeschrieben. Schreibrechte und Speicherplatz für den Medienordner prüfen und die Wiederherstellung wiederholen.', $restored, \count($missing), implode(', ', \array_slice($missing, 0, 5)).(\count($missing) > 5 ? ', …' : '')))) {
|
||||
return ['steps' => $steps, 'ok' => false];
|
||||
}
|
||||
// Eine Sicherung aus einer älteren Fassung bringt deren Datenbankschema mit. Der Code hier
|
||||
// ist neuer und erwartet Spalten, die es dann noch nicht gibt - das muss dastehen, sonst
|
||||
// sucht man die 500er an der falschen Stelle.
|
||||
@@ -367,20 +373,30 @@ final class Backup
|
||||
return ['count' => $count, 'bytes' => $bytes];
|
||||
}
|
||||
|
||||
private function restoreMedia(string $source): int
|
||||
/** @return array{int, list<string>} zurückgeschriebene Dateien und die Namen derer, die nicht ankamen */
|
||||
private function restoreMedia(string $source): array
|
||||
{
|
||||
if (!is_dir($source)) {
|
||||
return 0;
|
||||
return [0, []];
|
||||
}
|
||||
@mkdir($this->mediaDirectory, 0o775, true);
|
||||
$count = 0;
|
||||
$missing = [];
|
||||
foreach (glob($source.'/*') ?: [] as $file) {
|
||||
if (is_file($file) && @copy($file, $this->mediaDirectory.'/'.basename($file))) {
|
||||
if (!is_file($file)) {
|
||||
continue;
|
||||
}
|
||||
$target = $this->mediaDirectory.'/'.basename($file);
|
||||
$copied = @copy($file, $target);
|
||||
clearstatcache(true, $target);
|
||||
if ($copied && filesize($file) === @filesize($target)) {
|
||||
++$count;
|
||||
} else {
|
||||
$missing[] = basename($file);
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
return [$count, $missing];
|
||||
}
|
||||
|
||||
private function manifest(string $path): ?array
|
||||
|
||||
@@ -298,7 +298,12 @@ final class Installation
|
||||
}
|
||||
|
||||
$created = [];
|
||||
$this->db->transactional(function () use ($name, $locale, &$created): void {
|
||||
// Die Hauptsprache steht an der Website (ADR 111); Seiten, Bereiche und Menüs der
|
||||
// Hauptsprache liegen immer unter dem Schlüssel „de“, und so liest sie die öffentliche
|
||||
// Ausgabe. Vorher bekamen sie hier „en“ - eine englische Installation lieferte dann für
|
||||
// jede Seite, auch die Startseite, eine 404.
|
||||
$storage = 'de';
|
||||
$this->db->transactional(function () use ($name, $locale, $storage, &$created): void {
|
||||
if (!$this->db->fetchOne('SELECT id FROM website WHERE id = ?', ['default'])) {
|
||||
$this->db->insert('website', [
|
||||
'id' => 'default',
|
||||
@@ -310,27 +315,27 @@ final class Installation
|
||||
$this->db->update('website', ['name' => mb_substr($name, 0, 120), 'default_locale' => $locale], ['id' => 'default']);
|
||||
}
|
||||
|
||||
if (null === $this->pages->findPublished('home', $locale)) {
|
||||
$id = $this->pages->createPage('home', null, 'page', DemoContent::starterPage($name), $locale);
|
||||
if (null === $this->pages->findPublished('home', $storage)) {
|
||||
$id = $this->pages->createPage('home', null, 'page', DemoContent::starterPage($name), $storage);
|
||||
$page = $this->pages->findForEditor($id);
|
||||
$this->pages->publish($id, $page['draft_revision_id'], $page['version']);
|
||||
$created[] = 'Startseite';
|
||||
}
|
||||
foreach (DemoContent::LEGAL as $slug => $label) {
|
||||
if (null === $this->pages->findPublished($slug, $locale)) {
|
||||
$id = $this->pages->createPage($slug, null, 'page', DemoContent::legalPage($slug), $locale);
|
||||
if (null === $this->pages->findPublished($slug, $storage)) {
|
||||
$id = $this->pages->createPage($slug, null, 'page', DemoContent::legalPage($slug), $storage);
|
||||
$page = $this->pages->findForEditor($id);
|
||||
$this->pages->publish($id, $page['draft_revision_id'], $page['version']);
|
||||
$created[] = $label;
|
||||
}
|
||||
}
|
||||
foreach (DemoContent::starterAreas($name) as $kind => $area) {
|
||||
if (null === $this->partials->findByKind($kind, 'default', $locale)) {
|
||||
$this->partials->create($kind, 'default', $area['name'], $area['document'], $locale);
|
||||
if (null === $this->partials->findByKind($kind, 'default', $storage)) {
|
||||
$this->partials->create($kind, 'default', $area['name'], $area['document'], $storage);
|
||||
$created[] = $area['name'];
|
||||
}
|
||||
}
|
||||
$this->createMenu($locale, $created);
|
||||
$this->createMenu($storage, $created);
|
||||
});
|
||||
|
||||
$this->writeEnvironment(['SITE_ORIGIN' => $origin]);
|
||||
|
||||
+51
-6
@@ -121,7 +121,12 @@ final class SitePackage
|
||||
foreach ($files as $name) {
|
||||
$zip->addFile($this->mediaDirectory.'/'.$name, self::MEDIA.$name);
|
||||
}
|
||||
$zip->close();
|
||||
// Erst close() schreibt das Archiv. Scheitert es (Platte voll, Datei nicht lesbar), gäbe es
|
||||
// sonst ein Paket ohne Medien, dessen Import die Bilder der Zielwebsite löscht.
|
||||
if (true !== @$zip->close()) {
|
||||
@unlink($target);
|
||||
throw new InvalidPage('Das Paket ließ sich nicht vollständig schreiben. Freien Speicherplatz und Leserechte auf var/media prüfen.');
|
||||
}
|
||||
|
||||
return $target;
|
||||
}
|
||||
@@ -186,6 +191,7 @@ final class SitePackage
|
||||
try {
|
||||
$manifest = $this->checkedManifest($zip);
|
||||
$step('Paket prüfen', true, sprintf('„%s“ vom %s, Fassung %s, %d Seite(n), %d Mediendatei(en).', $manifest['website'], substr((string) $manifest['erstellt'], 0, 10), $manifest['fassung'], (int) ($manifest['inhalt']['page'] ?? 0), (int) $manifest['medien']));
|
||||
$this->checkedMedia($zip, $manifest);
|
||||
$tables = $this->checkedData($zip, $manifest);
|
||||
$this->validateDocuments($tables);
|
||||
$step('Inhalte prüfen', true, 'Alle Tabellen bekannt, alle Seiten- und Bereichsdokumente gültig.');
|
||||
@@ -234,7 +240,8 @@ final class SitePackage
|
||||
}
|
||||
$step('Medien ersetzen', true, sprintf('%d Datei(en) übernommen.', $moved));
|
||||
// Was der Webserver noch aus dem Abbild lieferte, gehört zur Website von vorher.
|
||||
$this->mirror?->prune();
|
||||
// Auch Varianten mit gleicher Kennung, aber neuem Inhalt - daher ganz leeren.
|
||||
$this->mirror?->clear();
|
||||
} finally {
|
||||
if (!$inWartung) {
|
||||
$this->updater->maintenance(false);
|
||||
@@ -305,6 +312,28 @@ final class SitePackage
|
||||
return $manifest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Das Paket muss jede Mediendatei enthalten, die sein Manifest zählt. Nach dem Import liegt im
|
||||
* Medienordner nur noch, was das Paket brachte - ein Paket mit fehlenden Dateien hinterließe
|
||||
* eine Website, deren Seiten auf gelöschte Bilder verweisen.
|
||||
*
|
||||
* @throws InvalidPage
|
||||
*/
|
||||
private function checkedMedia(\ZipArchive $zip, array $manifest): void
|
||||
{
|
||||
$found = 0;
|
||||
for ($i = 0; $i < $zip->numFiles; ++$i) {
|
||||
$name = (string) $zip->getNameIndex($i);
|
||||
if (str_starts_with($name, self::MEDIA) && 1 === preg_match(self::MEDIA_NAME, substr($name, \strlen(self::MEDIA)))) {
|
||||
++$found;
|
||||
}
|
||||
}
|
||||
$expected = $manifest['medien'] ?? null;
|
||||
if (!\is_int($expected) || $expected !== $found) {
|
||||
throw new InvalidPage(sprintf('Im Paket fehlen Mediendateien (%d von %s). Es ist unvollständig und wird nicht eingespielt.', $found, \is_int($expected) ? (string) $expected : '?'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, list<array<string, mixed>>>
|
||||
*
|
||||
@@ -434,6 +463,19 @@ final class SitePackage
|
||||
if (!@mkdir($target, 0o775, true)) {
|
||||
throw new \RuntimeException('Ein Arbeitsordner unter var/pakete ließ sich nicht anlegen.');
|
||||
}
|
||||
try {
|
||||
$this->extractMediaInto($zip, $target);
|
||||
} catch (\Throwable $e) {
|
||||
// Der Aufrufer kennt den Ordner noch nicht und könnte ihn nicht wegräumen.
|
||||
$this->remove($target);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $target;
|
||||
}
|
||||
|
||||
private function extractMediaInto(\ZipArchive $zip, string $target): void
|
||||
{
|
||||
for ($i = 0; $i < $zip->numFiles; ++$i) {
|
||||
$name = (string) $zip->getNameIndex($i);
|
||||
$base = substr($name, \strlen(self::MEDIA));
|
||||
@@ -446,12 +488,15 @@ final class SitePackage
|
||||
if (false === $stream || false === $out) {
|
||||
throw new \RuntimeException(sprintf('%s ließ sich nicht entpacken.', $base));
|
||||
}
|
||||
stream_copy_to_stream($stream, $out, self::MAX_FILE_BYTES);
|
||||
$copied = stream_copy_to_stream($stream, $out, self::MAX_FILE_BYTES);
|
||||
fclose($stream);
|
||||
fclose($out);
|
||||
$closed = fclose($out);
|
||||
// Bei voller Platte kommt eine verkürzte Datei an; replaceMedia vergleicht nur noch mit ihr.
|
||||
$expected = (int) ($zip->statIndex($i)['size'] ?? -1);
|
||||
if (!$closed || $copied !== $expected) {
|
||||
throw new \RuntimeException(sprintf('%s ließ sich nicht vollständig entpacken. Freien Speicherplatz prüfen.', $base));
|
||||
}
|
||||
}
|
||||
|
||||
return $target;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -376,6 +376,11 @@ final class Updater
|
||||
return array_slice(array_reverse($entries), 0, $lines);
|
||||
}
|
||||
|
||||
public function inMaintenance(): bool
|
||||
{
|
||||
return is_file($this->root.'/'.self::MAINTENANCE_FILE);
|
||||
}
|
||||
|
||||
public function maintenance(bool $on): void
|
||||
{
|
||||
$file = $this->root.'/'.self::MAINTENANCE_FILE;
|
||||
|
||||
Reference in new issue
Block a user