Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m7s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m11s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m16s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m18s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m49s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 2m46s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m41s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m33s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m0s
- Theme in den Einstellungen (Entwurf/veröffentlicht), Übernahme der Einstellungen aus Phase 0; statische CSS-Datei mit Hash beim Veröffentlichen - Logos hell/dunkel, Signet, App-Symbol → Favicon, Homescreen-Symbole, Web-App-Manifest; SVG-Bereinigung - Markenfarbe exakt, zweite Akzentfarbe, Kopfleiste hell/Marke/dunkel, Kontrastprüfung (WCAG AA) mit automatisch lesbarer Linkfarbe - Lokale Schriften (Latein), Überschriften-Schrift, eigene WOFF2-Schrift, Ecken, Dichte, Dunkelmodus-Regel - Anmeldeseite (geteilt/zentriert, Bild, Texte), Fußzeile, E-Mails im Design - Admin: Live-Vorschau (Startseite, Anmeldung, Beispielseite; hell/dunkel), Veröffentlichen, Verwerfen, Export/Import, Zurücksetzen, eigenes CSS - Admin-Bereich übernimmt Logo, Farbe und Favicon; Whitelabel Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
62 lines
2.1 KiB
PHP
62 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Support\Theme;
|
|
|
|
use DOMDocument;
|
|
use DOMElement;
|
|
use DOMXPath;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
/**
|
|
* Entfernt aus hochgeladenen SVG-Dateien alles Ausführbare (Skripte,
|
|
* Ereignis-Attribute, javascript:-Links, eingebettetes HTML). Logos werden
|
|
* öffentlich ausgeliefert und dürfen niemals Code enthalten.
|
|
*/
|
|
final class SvgSanitizer
|
|
{
|
|
public static function sanitizeFile(?string $path): void
|
|
{
|
|
if (! $path || ! str_ends_with(strtolower($path), '.svg')) {
|
|
return;
|
|
}
|
|
|
|
$disk = Storage::disk('uploads');
|
|
|
|
if (! $disk->exists($path)) {
|
|
return;
|
|
}
|
|
|
|
$clean = self::sanitize((string) $disk->get($path));
|
|
$clean === null ? $disk->delete($path) : $disk->put($path, $clean);
|
|
}
|
|
|
|
public static function sanitize(string $svg): ?string
|
|
{
|
|
$dom = new DOMDocument;
|
|
|
|
// Keine externen Entitäten, kein Netzwerkzugriff.
|
|
if (str_contains($svg, '<!ENTITY') || ! @$dom->loadXML($svg, LIBXML_NONET) || $dom->documentElement?->localName !== 'svg') {
|
|
return null;
|
|
}
|
|
|
|
$xpath = new DOMXPath($dom);
|
|
|
|
foreach (iterator_to_array($xpath->query('//*[local-name()="script" or local-name()="foreignObject" or local-name()="iframe" or local-name()="object" or local-name()="embed"]')) as $node) {
|
|
$node->parentNode->removeChild($node);
|
|
}
|
|
|
|
foreach (iterator_to_array($xpath->query('//*')) as $element) {
|
|
/** @var DOMElement $element */
|
|
foreach (iterator_to_array($element->attributes) as $attribute) {
|
|
$name = strtolower($attribute->nodeName);
|
|
$value = strtolower(preg_replace('/\s+/', '', $attribute->nodeValue));
|
|
|
|
if (str_starts_with($name, 'on') || (in_array($name, ['href', 'xlink:href', 'src'], true) && ! str_starts_with($value, '#') && ! str_starts_with($value, 'data:image/'))) {
|
|
$element->removeAttributeNode($attribute);
|
|
}
|
|
}
|
|
}
|
|
|
|
return $dom->saveXML($dom->documentElement);
|
|
}
|
|
}
|