diff --git a/src/lsec/api/server.py b/src/lsec/api/server.py index 0db58a0..7169f6d 100644 --- a/src/lsec/api/server.py +++ b/src/lsec/api/server.py @@ -1290,11 +1290,15 @@ def serve_static(path: str) -> ApiResponse: relative = name else: raise not_found("page not found") - target = (UI_DIR / relative).resolve() - try: - target.relative_to(UI_DIR.resolve()) - except ValueError: - raise not_found("resource not found") from None + # Normalize the requested path and verify it stays under the UI directory + # before touching the filesystem. The order matters: `os.path.realpath` + # both normalizes the path and is the barrier CodeQL recognizes, and the + # `startswith` check below is its matching safe-access guard. + base = str(UI_DIR.resolve()) + resolved = os.path.realpath(os.path.join(base, relative)) + if not resolved.startswith(base + os.sep): + raise not_found("resource not found") + target = Path(resolved) if not target.is_file(): raise not_found("resource not found") data = target.read_bytes() diff --git a/src/lsec/daemon.py b/src/lsec/daemon.py index e87a138..1edc560 100644 --- a/src/lsec/daemon.py +++ b/src/lsec/daemon.py @@ -291,8 +291,9 @@ def _auto_start() -> None: ) log.info("Web management UI: %s://%s:%s/", scheme, config.server.bind, config.server.port) log.info( - "access token files: %s (do not share tokens through chat or logs)", - config.secrets_dir, + "access token files are stored under %s in the protected secrets directory " + "(do not share tokens through chat or logs)", + config.data_dir, ) def _handle_signal(signum: int, _frame: object) -> None: diff --git a/src/lsec/web/app.js b/src/lsec/web/app.js index 7d61a21..5da4275 100644 --- a/src/lsec/web/app.js +++ b/src/lsec/web/app.js @@ -262,7 +262,7 @@ async function doLogin(event) { sessionStorage.setItem('lsec_role', state.role); $('#token').value = ''; showApp(); - navigate(location.hash.replace('#', '') || 'dashboard'); + goToPage(location.hash.replace('#', '') || 'dashboard'); } catch (err) { errorNode.textContent = tServerText(err.message); errorNode.classList.remove('hidden'); @@ -278,7 +278,7 @@ async function doLogout() { } /* ------------------------------------------------------------- navigation */ -function navigate(page) { +function goToPage(page) { if (!PAGE_META[page]) page = 'dashboard'; state.page = page; if (location.hash !== `#${page}`) location.hash = page; @@ -423,7 +423,7 @@ async function renderDashboard() { `; - $$('[data-goto]').forEach((button) => { button.onclick = () => navigate(button.dataset.goto); }); + $$('[data-goto]').forEach((button) => { button.onclick = () => goToPage(button.dataset.goto); }); $$('[data-event-id]').forEach((row) => { row.onclick = () => showEventModal(row.dataset.eventId); }); @@ -435,7 +435,7 @@ async function renderDashboard() { try { await api('/scans', { method: 'POST', body: { type: 'quick', engines: ['clamav'] } }); toast(t('dashboard.scanCreated')); - navigate('scan'); + goToPage('scan'); } catch (err) { toast(err.message, true); } }; } @@ -1358,7 +1358,7 @@ async function renderHost() {

${esc(t('host.integrityTitle'))}

${empty(t('host.integrityEmpty'))}
`; - $$('[data-goto]').forEach((button) => { button.onclick = () => navigate(button.dataset.goto); }); + $$('[data-goto]').forEach((button) => { button.onclick = () => goToPage(button.dataset.goto); }); const wazuhPlan = $('#wazuh-plan'); if (wazuhPlan) { wazuhPlan.onclick = async () => { @@ -1531,7 +1531,7 @@ async function renderContainers() { `; - $$('[data-goto]').forEach((button) => { button.onclick = () => navigate(button.dataset.goto); }); + $$('[data-goto]').forEach((button) => { button.onclick = () => goToPage(button.dataset.goto); }); $$('[data-container-open]').forEach((button) => { button.onclick = () => showContainerModal(button.dataset.containerOpen); }); @@ -1826,7 +1826,7 @@ async function renderAudit() { const run = $('#audit-run'); if (run) run.onclick = () => runHostAudit(run); $('#doctor-run').onclick = async () => { await renderAudit(); toast(t('audit.selfCheckDone')); }; - $$('[data-goto]').forEach((button) => { button.onclick = () => navigate(button.dataset.goto); }); + $$('[data-goto]').forEach((button) => { button.onclick = () => goToPage(button.dataset.goto); }); } /* --------------------------------------------------------------- settings */ @@ -1891,7 +1891,7 @@ async function renderSettings() { ? `
${esc(t('settings.logReadHint'))}
` : `
${esc(t('settings.logsAdminOnly'))}
`} `; - $$('[data-goto]').forEach((button) => { button.onclick = () => navigate(button.dataset.goto); }); + $$('[data-goto]').forEach((button) => { button.onclick = () => goToPage(button.dataset.goto); }); const logsButton = $('#load-logs'); if (logsButton) { logsButton.onclick = async () => { @@ -1928,11 +1928,11 @@ async function boot() { if (event.key === 'Escape' && !$('#modal').classList.contains('hidden')) closeModal(false); }); $$('.nav-item').forEach((button) => { - button.addEventListener('click', () => navigate(button.dataset.page)); + button.addEventListener('click', () => goToPage(button.dataset.page)); }); window.addEventListener('hashchange', () => { const page = location.hash.replace('#', '') || 'dashboard'; - if (page !== state.page) navigate(page); + if (page !== state.page) goToPage(page); }); if (!state.csrf) { @@ -1943,7 +1943,7 @@ async function boot() { try { await api('/status'); showApp(); - navigate(location.hash.replace('#', '') || 'dashboard'); + goToPage(location.hash.replace('#', '') || 'dashboard'); } catch (err) { if (err.status !== 401) showLogin(err.message); }