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
14 changes: 9 additions & 5 deletions src/lsec/api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions src/lsec/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 11 additions & 11 deletions src/lsec/web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
Expand Down Expand Up @@ -423,7 +423,7 @@ async function renderDashboard() {
</table></div>
</div>`;

$$('[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);
});
Expand All @@ -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); }
};
}
Expand Down Expand Up @@ -1358,7 +1358,7 @@ async function renderHost() {
<div class="card"><div class="card-head"><h2>${esc(t('host.integrityTitle'))}</h2></div>
${empty(t('host.integrityEmpty'))}
</div>`;
$$('[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 () => {
Expand Down Expand Up @@ -1531,7 +1531,7 @@ async function renderContainers() {
</ul>
</div>`;

$$('[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);
});
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -1891,7 +1891,7 @@ async function renderSettings() {
? `<div id="log-view" class="pre" style="max-height:320px">${esc(t('settings.logReadHint'))}</div>`
: `<div class="empty">${esc(t('settings.logsAdminOnly'))}</div>`}
</div>`;
$$('[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 () => {
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down
Loading