Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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 (`<img>`) eingebunden statt als SVG-Markup, Skripte in SVG-Dateien werden so nicht ausgeführt


### Fix: Verzeichnisschutz-Check des Cores meldet `redaxo/null` als unsicher

Expand Down
128 changes: 56 additions & 72 deletions assets/media-live-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function initQuickNavigationMediaLiveSearch() {
if (response.success) {
displayQuickNavSearchResults(response.results, container);
} else {
container.html('<div class="qn-live-search-no-results">Fehler: ' + (response.error || 'Unbekannter Fehler') + '</div>');
container.html('<div class="qn-live-search-no-results">Fehler: ' + qnEscape(response.error || 'Unbekannter Fehler') + '</div>');
}
},
error: function(xhr, status, error) {
Expand All @@ -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 { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c];
});
}

function displayQuickNavSearchResults(results, container) {
if (results.length === 0) {
container.html('<div class="qn-live-search-no-results">Keine Ergebnisse gefunden</div>');
container.show();
return;
}

var html = '';

$.each(results, function(index, item) {
var thumbnail = '';

if (item.thumbnail.type === 'image') {
thumbnail = '<img src="' + item.thumbnail.src + '" alt="' + item.thumbnail.alt + '" loading="lazy">';
} else if (item.thumbnail.type === 'svg') {
// inline SVG markup - already sanitized server-side
thumbnail = item.thumbnail.svg;
} else if (item.thumbnail.type === 'icon') {
thumbnail = '<i class="' + item.thumbnail.icon + '" title="' + item.thumbnail.title + '"></i>';
} else if (item.thumbnail.type === 'error') {
thumbnail = '<i class="' + item.thumbnail.icon + '" title="' + item.thumbnail.title + '" style="color: #dc3545;"></i>';
}

var detailUrl = '';
if (item.actions.edit) {
detailUrl = item.actions.edit.url;
var thumb = item.thumbnail || {};

if (thumb.type === 'image') {
thumbnail = '<img src="' + qnEscape(thumb.src) + '" alt="' + qnEscape(thumb.alt) + '" loading="lazy">';
} else if (thumb.type === 'icon') {
thumbnail = '<i class="' + qnEscape(thumb.icon) + '" title="' + qnEscape(thumb.title) + '"></i>';
} else if (thumb.type === 'error') {
thumbnail = '<i class="' + qnEscape(thumb.icon) + '" title="' + qnEscape(thumb.title) + '" style="color: #dc3545;"></i>';
}

if (item.actions.select) {
// Widget-Modus: Buttons untereinander anzeigen
html += '<div class="qn-live-search-item">' +
'<div class="qn-live-search-item-content">' +
'<div class="qn-live-search-thumb">' + thumbnail + '</div>' +
'<div class="qn-live-search-info">' +
'<div class="qn-live-search-title">' + item.title + '</div>' +
'<div class="qn-live-search-filename">' + item.filename + '</div>' +
'<div class="qn-live-search-meta">' + item.size + ' • ' + item.updatedate + '</div>' +
'</div>' +
'</div>' +
'<div class="qn-live-search-actions">';

// Übernehmen-Button
html += '<button type="button" class="btn btn-xs btn-select" onclick="';

if (item.actions.select.type === 'media') {
html += 'selectMedia(\'' + item.actions.select.filename + '\', \'' + item.actions.select.title + '\'); $(this).closest(\'.qn-media-live-search-results\').hide(); return false;';
} else if (item.actions.select.type === 'medialist') {
html += 'selectMedialist(\'' + item.actions.select.filename + '\', this); $(this).closest(\'.qn-media-live-search-results\').hide(); return false;';
}

html += '">' + item.actions.select.label + '</button>';

// Details-Button
if (detailUrl) {
html += '<a href="' + detailUrl + '" class="btn btn-xs btn-default">Details</a>';
}

html += '</div></div>';


var detailUrl = item.actions && item.actions.edit ? item.actions.edit.url : '';
var content = '<div class="qn-live-search-item-content">' +
'<div class="qn-live-search-thumb">' + thumbnail + '</div>' +
'<div class="qn-live-search-info">' +
'<div class="qn-live-search-title">' + qnEscape(item.title) + '</div>' +
'<div class="qn-live-search-filename">' + qnEscape(item.filename) + '</div>' +
'<div class="qn-live-search-meta">' + qnEscape(item.size) + ' • ' + qnEscape(item.updatedate) + '</div>' +
'</div>' +
'</div>';

if (item.actions && item.actions.select) {
// Widget-Modus: Übernehmen + Details; Auswahl über data-Attribute (kein Inline-JavaScript)
var select = item.actions.select;
html += '<div class="qn-live-search-item">' + content +
'<div class="qn-live-search-actions">' +
'<button type="button" class="btn btn-xs btn-select qn-media-select"' +
' data-type="' + qnEscape(select.type) + '"' +
' data-filename="' + qnEscape(select.filename) + '"' +
' data-title="' + qnEscape(select.title) + '">' + qnEscape(select.label) + '</button>' +
(detailUrl ? '<a href="' + qnEscape(detailUrl) + '" class="btn btn-xs btn-default">Details</a>' : '') +
'</div></div>';
} else if (detailUrl) {
// Normaler Modus: Komplettes Element als Link zur Detailansicht
html += '<a href="' + detailUrl + '" class="qn-live-search-item" style="color: inherit; text-decoration: none;">' +
'<div class="qn-live-search-item-content">' +
'<div class="qn-live-search-thumb">' + thumbnail + '</div>' +
'<div class="qn-live-search-info">' +
'<div class="qn-live-search-title">' + item.title + '</div>' +
'<div class="qn-live-search-filename">' + item.filename + '</div>' +
'<div class="qn-live-search-meta">' + item.size + ' • ' + item.updatedate + '</div>' +
'</div>' +
'</div>' +
'</a>';
html += '<a href="' + qnEscape(detailUrl) + '" class="qn-live-search-item" style="color: inherit; text-decoration: none;">' + content + '</a>';
} else {
// Fallback ohne Link
html += '<div class="qn-live-search-item">' +
'<div class="qn-live-search-item-content">' +
'<div class="qn-live-search-thumb">' + thumbnail + '</div>' +
'<div class="qn-live-search-info">' +
'<div class="qn-live-search-title">' + item.title + '</div>' +
'<div class="qn-live-search-filename">' + item.filename + '</div>' +
'<div class="qn-live-search-meta">' + item.size + ' • ' + item.updatedate + '</div>' +
'</div>' +
'</div>' +
'</div>';
html += '<div class="qn-live-search-item">' + content + '</div>';
}
});

container.html(html).show();
}
}

// Ü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();
});
45 changes: 7 additions & 38 deletions lib/ApiFunction/MediaSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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 = [];

Expand All @@ -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 = [];
Expand Down Expand Up @@ -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 (<img> 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 <script> tags and on* attributes to avoid JS execution
$svg = preg_replace('#<\s*script[^>]*>.*?<\s*/\s*script\s*>#is', '', $svg);
// remove javascript: URIs
$svg = preg_replace_callback('#(<[^>]+>)#', function ($m) {
return preg_replace('#\s(on[a-z]+)\s*=\s*("[^"]*"|' . "'[^']*'" . ')#i', '', $m[1]);
}, $svg);
// strip xml prolog
$svg = preg_replace('/^\s*<\?xml[^>]+>\s*/i', '', $svg);

return [
'type' => 'svg',
'svg' => $svg,
'alt' => $media->getTitle() ?: $media->getFilename(),
];
}
}
} catch (Exception $e) {
// fall through to icon
}
return [
'type' => 'image',
'src' => rex_url::media($media->getFileName()),
'alt' => $media->getTitle() ?: $media->getFilename(),
];
}

$isImage = in_array($ext, ['jpg', 'jpeg', 'png', 'gif', 'webp']);
Expand Down
Loading