From 82dd6e026a8f639d27997161692b0439831adaba Mon Sep 17 00:00:00 2001 From: JonKazama-Hellion Date: Thu, 16 Apr 2026 20:18:42 +0200 Subject: [PATCH] fix(security): validate background URL before CSS injection Add isValidBgUrl() that only allows blob: and data:image/ protocols. Applied in applySettings() and the manual URL input handler. Prevents CSS injection via manipulated bgUrl storage values. --- src/js/settings.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/js/settings.js b/src/js/settings.js index 29408e2..9a9d50d 100644 --- a/src/js/settings.js +++ b/src/js/settings.js @@ -23,6 +23,17 @@ function closeThemeModal() { overlay.classList.remove('active'); } +/** + * Prueft ob eine Background-URL sicher fuer CSS-Einbettung ist. + * Erlaubt nur blob: und data:image/ Protokolle (aus File Upload). + * @param {string} url + * @returns {boolean} + */ +function isValidBgUrl(url) { + return typeof url === 'string' && url.length > 0 && + (url.startsWith('blob:') || url.startsWith('data:image/')); +} + // ---- ACCORDION ---- function initAccordion() { const defaultOpen = new Set(['widgets']); @@ -89,8 +100,10 @@ function applySettings() { applyTheme(settings.theme || 'nebula', !!settings.bgUrl); - if (settings.bgUrl) { + if (settings.bgUrl && isValidBgUrl(settings.bgUrl)) { document.getElementById('bgLayer').style.backgroundImage = `url('${settings.bgUrl}')`; + } else if (settings.bgUrl) { + settings.bgUrl = ''; } } @@ -168,6 +181,10 @@ function bindSettingsEvents() { }); document.getElementById('btnApplyBg').addEventListener('click', async () => { const url = document.getElementById('bgUrlInput').value.trim(); + if (url && !isValidBgUrl(url)) { + await HellionDialog.alert(t('settings.bg_invalid_url'), { type: 'danger', title: t('settings.bg_invalid_url.title') }); + return; + } settings.bgUrl = url; document.getElementById('bgLayer').style.backgroundImage = url ? `url('${url}')` : ''; await saveSettings();