From 2b783f23e8ebb2cd85d02015a8718cb17fcf9c49 Mon Sep 17 00:00:00 2001 From: Paul Donald Date: Mon, 13 Oct 2025 14:33:23 +0200 Subject: [PATCH] luci-mod-system: minor code fixes for repokeys and sshkeys Signed-off-by: Paul Donald (cherry picked from commit 850867b6e4ebe437889f6e6ef630b6a6e6c033b7) --- .../luci-static/resources/view/system/repokeys.js | 14 ++++++++++---- .../luci-static/resources/view/system/sshkeys.js | 10 +++++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/modules/luci-mod-system/htdocs/luci-static/resources/view/system/repokeys.js b/modules/luci-mod-system/htdocs/luci-static/resources/view/system/repokeys.js index a5a247abd2..6703a50970 100644 --- a/modules/luci-mod-system/htdocs/luci-static/resources/view/system/repokeys.js +++ b/modules/luci-mod-system/htdocs/luci-static/resources/view/system/repokeys.js @@ -19,7 +19,7 @@ const safeList = [ ]; function isFileInSafeList(file){ - for (name of safeList) { + for (let name of safeList) { if (file === name) return true; } @@ -27,7 +27,7 @@ function isFileInSafeList(file){ } function normalizeKey(s) { - return s.replace(/\s+/g, ' ').trim(); + return s?.replace(/\s+/g, ' ')?.trim(); } function determineKeyEnv() { @@ -51,10 +51,16 @@ function listKeyFiles() { ); } +function safeText(str) { + return String(str).replace(/[&<>"']/g, s => ({ + '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' + }[s])); +} + function renderKeyItem(pubkey) { const safeFile = isFileInSafeList(pubkey?.filename); const lines = pubkey?.key?.trim()?.split('\n').map(line => - [ E('br'), E('code', line) ] + [ E('br'), E('code', {}, [ safeText(line) ]) ] ).flat(); return E('div', { class: 'item', @@ -62,7 +68,7 @@ function renderKeyItem(pubkey) { 'data-file': pubkey?.filename, 'data-key': normalizeKey(pubkey?.key) }, [ - E('strong', [ pubkey?.filename || _('Unnamed key') ]), + E('strong', {}, [ pubkey?.filename || _('Unnamed key') ]), ...lines ]); } diff --git a/modules/luci-mod-system/htdocs/luci-static/resources/view/system/sshkeys.js b/modules/luci-mod-system/htdocs/luci-static/resources/view/system/sshkeys.js index ce983c3228..b953a8f9ab 100644 --- a/modules/luci-mod-system/htdocs/luci-static/resources/view/system/sshkeys.js +++ b/modules/luci-mod-system/htdocs/luci-static/resources/view/system/sshkeys.js @@ -118,14 +118,14 @@ function renderKeyItem(pubkey) { click: isReadonlyView ? null : removeKey, 'data-key': pubkey.src }, [ - E('strong', [ pubkey.comment || _('Unnamed key') ]), E('br'), - E('small', [ + E('strong', {}, [ pubkey.comment || _('Unnamed key') ]), E('br'), + E('small', {}, [ '%s, %s'.format(pubkey.type, pubkey.curve || _('%d Bit').format(pubkey.bits)), - pubkey.options ? E([], [ + pubkey.options ? E([], {}, [ ' / ', _('Options:'), ' ', - E('code', Object.keys(pubkey.options).sort().join(', ')) + E('code', {}, [Object.keys(pubkey.options).sort().join(', ')]) ]) : '', - E('br'), E('code', pubkey.fprint) + E('br'), E('code', {}, [pubkey.fprint]) ]) ]); } -- 2.30.2