diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ecaab2..22976d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,17 @@ # Changelog -## Unveröffentlicht +## 9.3.1 – 2026-10-30 + +### Fix: Medien-Live-Suche bricht ab – „Call to undefined function …\error_log()“ (#214) + +- Die Medien-Live-Suche rief bei jeder Suche `error_log()` auf (Debug-Reste). Ist die Funktion beim Hoster per `disable_functions` gesperrt, brach die Suche mit einem Fehler ab. Die Aufrufe sind entfernt – sie schrieben außerdem Suchbegriffe und SQL ins Server-Log + +### Sicherheit: Medien-Live-Suche maskiert alle Werte + +- Titel, Dateinamen und Meldungen werden vor der Ausgabe maskiert; Titel mit `'`, `"` oder `<` brechen die Trefferliste nicht mehr +- „Übernehmen“ arbeitet mit `data`-Attributen statt Inline-JavaScript (`onclick`) +- SVG-Vorschauen werden als Bild (``) eingebunden statt als SVG-Markup, Skripte in SVG-Dateien werden so nicht ausgeführt + ### Fix: Verzeichnisschutz-Check des Cores meldet `redaxo/null` als unsicher diff --git a/assets/media-live-search.js b/assets/media-live-search.js index d4319a9..6bcd6b6 100644 --- a/assets/media-live-search.js +++ b/assets/media-live-search.js @@ -109,7 +109,7 @@ function initQuickNavigationMediaLiveSearch() { if (response.success) { displayQuickNavSearchResults(response.results, container); } else { - container.html('
Fehler: ' + (response.error || 'Unbekannter Fehler') + '
'); + container.html('
Fehler: ' + qnEscape(response.error || 'Unbekannter Fehler') + '
'); } }, error: function(xhr, status, error) { @@ -123,91 +123,75 @@ function initQuickNavigationMediaLiveSearch() { } } + // Werte aus der Datenbank (Titel, Dateiname …) immer maskieren + function qnEscape(value) { + return String(value == null ? '' : value).replace(/[&<>"']/g, function (c) { + return { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]; + }); + } + function displayQuickNavSearchResults(results, container) { if (results.length === 0) { container.html('
Keine Ergebnisse gefunden
'); container.show(); return; } - + var html = ''; - + $.each(results, function(index, item) { var thumbnail = ''; - - if (item.thumbnail.type === 'image') { - thumbnail = '' + item.thumbnail.alt + ''; - } else if (item.thumbnail.type === 'svg') { - // inline SVG markup - already sanitized server-side - thumbnail = item.thumbnail.svg; - } else if (item.thumbnail.type === 'icon') { - thumbnail = ''; - } else if (item.thumbnail.type === 'error') { - thumbnail = ''; - } - - var detailUrl = ''; - if (item.actions.edit) { - detailUrl = item.actions.edit.url; + var thumb = item.thumbnail || {}; + + if (thumb.type === 'image') { + thumbnail = '' + qnEscape(thumb.alt) + ''; + } else if (thumb.type === 'icon') { + thumbnail = ''; + } else if (thumb.type === 'error') { + thumbnail = ''; } - - if (item.actions.select) { - // Widget-Modus: Buttons untereinander anzeigen - html += '
' + - '
' + - '
' + thumbnail + '
' + - '
' + - '
' + item.title + '
' + - '
' + item.filename + '
' + - '
' + item.size + ' • ' + item.updatedate + '
' + - '
' + - '
' + - '
'; - - // Übernehmen-Button - html += ''; - - // Details-Button - if (detailUrl) { - html += 'Details'; - } - - html += '
'; - + + var detailUrl = item.actions && item.actions.edit ? item.actions.edit.url : ''; + var content = '
' + + '
' + thumbnail + '
' + + '
' + + '
' + qnEscape(item.title) + '
' + + '
' + qnEscape(item.filename) + '
' + + '
' + qnEscape(item.size) + ' • ' + qnEscape(item.updatedate) + '
' + + '
' + + '
'; + + if (item.actions && item.actions.select) { + // Widget-Modus: Übernehmen + Details; Auswahl über data-Attribute (kein Inline-JavaScript) + var select = item.actions.select; + html += '
' + content + + '
' + + '' + + (detailUrl ? 'Details' : '') + + '
'; } else if (detailUrl) { // Normaler Modus: Komplettes Element als Link zur Detailansicht - html += '' + - '
' + - '
' + thumbnail + '
' + - '
' + - '
' + item.title + '
' + - '
' + item.filename + '
' + - '
' + item.size + ' • ' + item.updatedate + '
' + - '
' + - '
' + - '
'; + html += '' + content + ''; } else { // Fallback ohne Link - html += '
' + - '
' + - '
' + thumbnail + '
' + - '
' + - '
' + item.title + '
' + - '
' + item.filename + '
' + - '
' + item.size + ' • ' + item.updatedate + '
' + - '
' + - '
' + - '
'; + html += '
' + content + '
'; } }); - + container.html(html).show(); - } \ No newline at end of file + } + + // Übernehmen-Knopf (Medien-Widget): Core-Funktionen selectMedia / selectMedialist des Medienpools + $(document).off('click.quicknavselect').on('click.quicknavselect', '.qn-media-select', function (e) { + e.preventDefault(); + var btn = $(this); + if (btn.attr('data-type') === 'medialist' && typeof window.selectMedialist === 'function') { + window.selectMedialist(String(btn.attr('data-filename')), this); + } else if (typeof window.selectMedia === 'function') { + window.selectMedia(String(btn.attr('data-filename')), String(btn.attr('data-title'))); + } + btn.closest('.qn-media-live-search-results').hide(); + }); \ No newline at end of file diff --git a/lib/ApiFunction/MediaSearch.php b/lib/ApiFunction/MediaSearch.php index 72ea5e8..3fff6ac 100644 --- a/lib/ApiFunction/MediaSearch.php +++ b/lib/ApiFunction/MediaSearch.php @@ -18,9 +18,6 @@ class MediaSearch extends rex_api_function { public function execute() { - // Debug-Logging - error_log('MediaSearch API called'); - // Content-Type vor jeder Ausgabe setzen if (!headers_sent()) { header('Content-Type: application/json; charset=utf-8'); @@ -56,9 +53,6 @@ public function execute() } try { - // Debug: Log search parameters - error_log('MediaSearch API: term=' . $searchTerm . ', category=' . $categoryId); - // Medien suchen - korrigierter Filter $where = []; @@ -76,21 +70,15 @@ public function execute() // Types-Filter (falls vorhanden) if (!empty($types)) { $typeArray = explode(',', $types); - $typePlaceholders = str_repeat('?,', count($typeArray) - 1) . '?'; $where[] = 'm.filename REGEXP ?'; $params[] = '\.(' . implode('|', array_map('preg_quote', $typeArray)) . ')$'; } // SQL Query aufbauen $sql = rex_sql::factory(); - $query = 'SELECT m.* FROM ' . rex::getTable('media') . ' m'; - if (!empty($where)) { - $query .= ' WHERE ' . implode(' AND ', $where); - } + $query = 'SELECT m.* FROM ' . rex::getTable('media') . ' m WHERE ' . implode(' AND ', $where); $query .= ' ORDER BY m.updatedate DESC LIMIT 10'; - error_log('MediaSearch SQL: ' . $query . ' | Params: ' . json_encode($params)); - $sql->setQuery($query, $params); $results = []; @@ -142,32 +130,13 @@ private function generateThumbnail($media) { $ext = strtolower($media->getExtension()); - // SVG: read file and return inline SVG markup (sanitized) so MediaManager effects are not used + // SVG als Bild einbinden ( führt keine Skripte im SVG aus) – kein Inline-Markup, keine MediaManager-Effekte if ($ext === 'svg') { - try { - $filePath = \rex_path::media($media->getFileName()); - if (is_file($filePath) && is_readable($filePath)) { - $svg = (string) @file_get_contents($filePath); - if ($svg !== '') { - // Basic sanitization: remove